đŸ—ƒī¸ CSS Selectors - āύāϤ⧁āύ, āĻĒ⧁āϰāĻžāϤāύ āĻāĻŦāĻ‚ āĻ…āĻ¨ā§āϝāĻžāĻ¨ā§āϝ

~ + ^ $ | >

āωāĻĒāϰ⧇āϰ āĻāχ āϚāĻŋāĻšā§āύāϗ⧁āϞ⧋āϰ āϏāĻžāĻĨ⧇ āĻĒ⧁āϰ⧋āύ⧋ āĻĄā§‡āϭ⧇āϞāĻĒāĻžāϰāϰāĻž āĻ•āĻŽāĻŦ⧇āĻļāĻŋ āĻĒāϰāĻŋāϚāĻŋāϤ āĻšāϞ⧇āĻ“, āύāϤ⧁āύ āĻšāĻŋāϏ⧇āĻŦ⧇ āφāĻŽāĻžāϰ āĻ•āĻžāϛ⧇ āĻāϗ⧁āϞ⧋ āĻ›āĻŋāϞ āĻāϞāĻŋā§Ÿā§‡āύ āϏāĻžāχāύ (we are not alone :alien:) (āĻŦā§āϝāĻžāĻ•āĻ—ā§āϰāĻžāωāĻ¨ā§āĻĄ āĻŽāĻŋāωāϜāĻŋāĻ•)āĨ¤ āφāĻŽāĻŋ āϗ⧁āĻ—āϞ āĻ•āϰāϤāĻžāĻŽ āĻāĻ­āĻžāĻŦ⧇- What is this symble in CSS? āφāϰ āĻ•āĻžāωāϕ⧇ āϜāĻŋāĻœā§āĻžā§‡āϏ āĻ•āϰāĻžāϰ āϏāĻŽā§Ÿ āĻŦāϞāϤāĻžāĻŽ- āĻāχāϗ⧁āϞāĻž āϕ⧀?

CSS Selector āĻāϰ āφāϰ⧇āĻ•āϟāĻž āĻāĻžāĻŽā§‡āϞāĻžāϰ āϜāĻžā§ŸāĻ—āĻž āĻšāϞ⧋- pseudo selectors, pseudo elements, pseudo classes :thinking: āĻŽāĻžāύ⧇, āϕ⧋āύāϟāĻž āϕ⧀?

::before ::after āĻ¸ā§āϝ⧁āĻĄā§‹ āϏāĻŋāϞ⧇āĻ•ā§āϟāϰ āύāĻžāĻ•āĻŋ āĻ•ā§āϞāĻžāϏ, āύāĻžāĻ•āĻŋ āĻŦāĻžāχāϏāĻžāχāϕ⧇āϞ?
:hover :focus āĻāϗ⧁āϞāĻž āĻ•āĻŋ āĻ¸ā§āϝ⧁āĻĄā§‹ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟ āύāĻžāĻ•āĻŋ āĻ•ā§āϞāĻžāϏ, āύāĻžāĻ•āĻŋ āĻŽāĻžāĻ¸ā§āϟāĻžāϰāĻŽāĻžāχāĻ¨ā§āĻĄ?

āφāϏ⧇āύ āφāϜāϕ⧇ āφāϞ⧋āϚāύāĻžāϰ āĻŽāĻžāĻ§ā§āϝāĻŽā§‡ āĻāχ āĻŦāĻŋāώ⧟āϗ⧁āϞāĻžāϰ āϏāĻŽāĻžāϧāĻžāύ āĻ•āϰāĻŋāĨ¤ āĻĒā§āϰāϤāĻŋāϟāĻžāϰ āϏ⧁āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āύāĻžāĻŽ, āĻ•āĻžāϜ, āĻāĻŦāĻ‚ āϏāĻŽā§āĻ­āĻŦ āĻšāϞ⧇ CSS āĻāϰ āϕ⧋āύ āĻ­āĻžāĻ°ā§āϏāύ⧇āϰ āĻ…āĻ¨ā§āϤāĻ°ā§āϭ⧁āĻ•ā§āϤ, āĻāχ āĻŦāĻŋāώ⧟āϗ⧁āϞ⧋āĻ“ āϜāĻžāύāĻŦāĨ¤ āϤāĻŦ⧇ āĻļ⧁āϰ⧁ āĻ•āϰāĻžāϰ āφāϗ⧇ āφāϰ⧇āĻ•āϟāĻž āĻŦāĻŋāώ⧟ āĻŦāϞ⧇ āĻ¨ā§‡ā§ŸāĻž āĻ­āĻžāϞāĨ¤

āφāϜāϕ⧇ āĻļ⧁āϧ⧁ CSS Selector āĻāϰ āύāĻžāĻŽ āĻāĻŦāĻ‚ āĻļā§āϰ⧇āĻŖā§€āĻŦāĻŋāĻ¨ā§āϝāĻžāϏ āϤāĻĨāĻž āĻ•ā§āϞāĻžāϏāĻŋāĻĢāĻŋāĻ•ā§āϝāĻžāĻļāĻžāύ āύāĻŋā§Ÿā§‡ āφāĻŽāĻžāĻĻ⧇āϰ āĻŽāĻ§ā§āϝ⧇ āϝ⧇ āĻāĻ•āϟāĻž āϧ⧋āρāϝāĻŧāĻžāĻļāĻž āφāϛ⧇, āϏ⧇āϟāĻž āĻ•ā§āϞāĻŋ⧟āĻžāϰ āĻ•āϰāĻžāϰ āĻšā§‡āĻˇā§āϟāĻž āĻ•āϰāĻŦā§‹āĨ¤ āϏāĻŦ āϏāĻŋāϞ⧇āĻ•ā§āϟāϰ āύāĻŋā§Ÿā§‡ āφāϞāĻžāĻĻāĻž āφāϞāĻžāĻĻāĻž āφāϞ⧋āϚāύāĻž āĻ•āϰāϤ⧇ āϗ⧇āϞ⧇ āϏāĻŋāϞ⧇āĻ•ā§āϟāϰāĻĒāĻŋāĻĄāĻŋ⧟āĻž āĻšā§Ÿā§‡ āϝāĻžāĻŦ⧇, āĻāĻŦāĻ‚ āϏāĻ¤ā§āϝāĻŋ āĻŦāϞāϤ⧇ āĻ•āĻŋ, āφāϞāĻžāĻĻāĻž āφāϞ⧋āϚāύāĻžāϰ āĻĒā§āĻ°ā§Ÿā§‹āϜāύāĻ“ āύāĻžāχāĨ¤ āĻŸā§‡āĻŦāĻŋāϞ āφāĻ•āĻžāϰ⧇ āύāĻžāĻŽ, āĻ­āĻžāĻ°ā§āϏāύ, āĻ•āĻžāϜ āĻāĻŦāĻ‚ āϛ⧋āĻŸā§āϟ āĻāĻ•āϟāĻž āωāĻĻāĻžāĻšāϰāĻŖ, āĻāχāϟ⧁āϕ⧁āχ āĻ…āύ⧇āĻ•āĨ¤

[ā§§] āχāĻ‚āϰ⧇āϜāĻŋ pseudo āĻļāĻŦā§āĻĻ⧇āϰ āĻŦāĻžāĻ‚āϞāĻž āĻ…āύ⧇āĻ•āϟāĻž āĻāχāϰāĻ•āĻŽ- āĻ•ā§ƒāĻ¤ā§āϰāĻŋāĻŽ, āĻ›āĻĻā§āĻŽ āχāĻ¤ā§āϝāĻžāĻĻāĻŋāĨ¤ āĻ…āĻ°ā§āĻĨāĻžā§Ž, Pseudo Selector āφāϏāϞ⧇ āϕ⧋āύ āĻ¸ā§āĻŦāϤāĻ¨ā§āĻ¤ā§āϰ āϏāĻŋāϞ⧇āĻ•ā§āϟāϰ āύāĻž, āĻāϰ āύāĻŋāϜāĻ¸ā§āĻŦ āϕ⧋āύ āϏāĻ¤ā§āϤāĻž āύāĻžāχāĨ¤ āϏ⧇ āĻ•ā§ƒāĻ¤ā§āϰāĻŋāĻŽ āĻĒāĻĻā§āϧāϤāĻŋāϤ⧇
āĻ…āĻ¨ā§āϝ āĻāĻ•āϟāĻž āϏāĻŋāϞ⧇āĻ•ā§āϟāϰ⧇āϰ āĻ›āĻĻā§āĻŽāĻŦ⧇āĻļ⧇ āϤāĻžāϰ āĻ•āĻžāϜ āĻ•āϰ⧇āĨ¤

āϕ⧋āύāϟāĻž āϕ⧀?

  • ::before ::after āĻāϰ āĻŽāϤ āϝāĻžāϰāĻž āφāϛ⧇, āϝ⧇āĻŽāύ, ‌‌::selection ::marker ::first-line ::first-letter ::placeholder ::backdrop āχāĻ¤ā§āϝāĻžāĻĻāĻŋ, āĻāϗ⧁āϞ⧋āϕ⧇ āĻŦāϞāĻž āĻšā§Ÿ- ‌‌Pseudo Element (āĻ¸ā§āϝ⧁āĻĄā§‹ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟ)āĨ¤
    • āĻāϰāĻž āĻĄāĻŦāϞ āϕ⧋āϞāύ :: āĻĻāĻŋā§Ÿā§‡ āĻļ⧁āϰ⧁ āĻšā§ŸāĨ¤ āϤāĻŦ⧇ āĻ•āĻŋāϛ⧁ āĻŦā§āϰāĻžāωāϜāĻžāϰ⧇āϰ āĻĒ⧁āϰ⧋āύ⧋ āĻ­āĻžāĻ°ā§āϏāύāϗ⧁āϞ⧋āϤ⧇ āφāϗ⧇āϰ āϏāĻŋāĻ™ā§āϗ⧇āϞ āϕ⧋āϞāύ : āĻĻāĻŋā§Ÿā§‡āĻ“ āĻ•āĻžāϜ āĻ•āϰ⧇āĨ¤ āĻāĻĻ⧇āϰ āĻ•āĻžāϜ āĻšāϞ⧋ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟ āύāĻŋā§Ÿā§‡āĨ¤ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āĻŸā§‡āϰ āφāϗ⧇/āĻĒāϰ⧇ (::before ::after) āĻ•āĻŋāϛ⧁ āĻ•āϰāĻž, āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āĻŸā§‡āϰ āĻĒā§āϰāĻĨāĻŽ āϞāĻžāχāύ (::first-line) āĻŦāĻž (::first-letter), āχāĻ¤ā§āϝāĻžāĻĻāĻŋ āύāĻŋā§Ÿā§‡ āĻ•āĻžāϜ āĻ•āϰāĻž, āĻŽā§‹āϟāĻ•āĻĨāĻž āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟ-āϕ⧇āĻ¨ā§āĻĻā§āϰāĻŋāĻ• āĻ•āĻžāϜāĻ•āĻ°ā§āĻŽ āϏāĻŦāĨ¤
  • :hover :focus āĻāϰ āĻŽāϤ āϝāĻžāϰāĻž āφāϛ⧇, āϝ⧇āĻŽāύ, :visited :first-child :nth-child() :checked :target :has() :is() :where() āχāĻ¤ā§āϝāĻžāĻĻāĻŋ, āĻāϗ⧁āϞ⧋āϕ⧇ āĻŦāϞāĻž āĻšā§Ÿ- Pseudo Class (āĻ¸ā§āϝ⧁āĻĄā§‹ āĻ•ā§āϞāĻžāϏ)āĨ¤
    • āĻāϰāĻž āĻļ⧁āϰ⧁ āĻšā§Ÿ āϏāĻŋāĻ™ā§āϗ⧇āϞ āϕ⧋āϞāύ āĻĻāĻŋā§Ÿā§‡āĨ¤ āĻāĻĻ⧇āϰ āĻ•āĻžāϜ āĻšāϞ⧋ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āĻŸā§‡āϰ āĻ…āĻŦāĻ¸ā§āĻĨāĻžāϰ (State) āωāĻĒāϰ āĻ­āĻŋāĻ¤ā§āϤāĻŋ āĻ•āϰ⧇ āĻ•āĻžāϜ āĻ•āϰāĻž, āϝ⧇āĻŽāύ- :hover :focus :target :checked āχāĻ¤ā§āϝāĻžāĻĻāĻŋ, āĻ…āĻĨāĻŦāĻž āĻ­āĻŋāĻ¨ā§āύ āφāϰ⧇āĻ•āϟāĻŋ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟāϕ⧇ āϏāĻŋāϞ⧇āĻ•ā§āϟ āĻ•āϰāĻž- :has() :is() :where() āχāĻ¤ā§āϝāĻžāĻĻāĻŋāĨ¤
  • āφāϰ āĻāχ āĻĻ⧁āχ āϧāϰāύ⧇āϰ āϏāĻŋāϞ⧇āĻ•ā§āϟāϰāϕ⧇ Pseudo Selector āĻŦāϞ⧇āĨ¤

āĻ•āĻŋāϛ⧁ āĻ•āĻŽāύ Pseudo Selector āύāĻŋāĻšā§‡ āĻŸā§‡āĻŦāĻŋāϞ āφāĻ•āĻžāϰ⧇ āĻĻā§‡ā§ŸāĻž āĻšāϞ⧋, āĻ­āĻžāĻ°ā§āϏāύ āĻāĻŦāĻ‚ āϏāĻ‚āĻ•ā§āώāĻŋāĻĒā§āϤ āĻĒāϰāĻŋāϚāĻŋāϤāĻŋāϏāĻšāĨ¤ āĻāϗ⧁āϞ⧋ āĻ›āĻžā§œāĻž āφāϰāĻ“ āĻ…āύ⧇āĻ• āφāϛ⧇, āϏāĻžāĻ°ā§āϚ āĻ•āϰāϞ⧇āχ āĻĒāĻžāĻŦ⧇āύāĨ¤


CSS Pseudo Elements


Pseudo Elements Version Short Definition & Example
::first-line CSS1 Styles the first line of a block-level element.
Example:
p::first-line { color: blue; }
::first-letter CSS1 Styles the first letter of a block-level element.
Example:
p::first-letter { font-size: 2em; }
::before CSS2 Inserts content before an element’s content.
Example:
p::before { content: "Note: "; }
::after CSS2 Inserts content after an element’s content.
Example:
p::after { content: " End."; }
::selection CSS3 Styles the portion of text highlighted by the user.
Example:
::selection { background: yellow; }
::placeholder CSS3 Styles the placeholder text of an input field.
Example:
input::placeholder { color: grey; }
::marker CSS3 Styles the bullet or numbering of list items.
Example:
li::marker { color: red; }
::backdrop CSS4 Styles the backdrop of an element in fullscreen mode.
Example:
::backdrop { background: black; }
::file-selector-button CSS4 Styles the button in <input type="file">.
Example:
input::file-selector-button { color: blue; }

CSS Pseudo Classes


Pseudo Classes Version Short Definition & Example
:link CSS1 Styles unvisited links.
Example:
a:link { color: blue; }
:visited CSS1 Styles visited links.
Example:
a:visited { color: purple; }
:hover CSS2 Styles elements when the mouse hovers over them.
Example:
a:hover { color: red; }
:focus CSS2 Styles elements when they are focused.
Example:
input:focus { border-color: green; }
:first-child CSS2 Targets the first child element of its parent.
Example:
p:first-child { font-weight: bold; }
:nth-child() CSS3 Matches elements based on their position among siblings.
Example:
p:nth-child(2) { color: blue; }
:nth-of-type() CSS3 Matches elements based on their type and position.
Example:
p:nth-of-type(2) { color: red; }
:not() CSS3 Excludes elements that match the given selector.
Example:
p:not(.highlight) { color: grey; }
:enabled CSS3 Styles form elements that are enabled.
Example:
input:enabled { background: white; }
:disabled CSS3 Styles form elements that are disabled.
Example:
input:disabled { background: grey; }
:checked CSS3 Styles elements that are checked (like checkboxes or radio buttons).
Example:
input:checked { background: yellow; }
:target CSS3 Styles elements that are the target of a URL fragment.
Example:
#section:target { background: yellow; }
:has() CSS4 Matches elements that contain specific child elements.
Example:
div:has(img) { border: 1px solid red; }
:is() CSS4 Matches elements that fit any of the selectors in the argument list.
Example:
p:is(.class1, .class2) { color: blue; }
:where() CSS4 Similar to :is() but with zero specificity.
Example:
:where(h1, h2) { margin: 0; }

Combinator āĻāĻŦāĻ‚ Attribute selector

[⧍] āĻļ⧁āϰ⧁āϤ⧇ āϝ⧇ āϚāĻŋāĻšā§āύāϗ⧁āϞ⧋āϰ āĻ•āĻĨāĻž āĻŦāϞ⧇āĻ›āĻŋāϞāĻžāĻŽ, āϏ⧇āϗ⧁āϞ⧋āĻ“ āĻĻ⧁āχ āĻ­āĻžāϗ⧇ āĻŦāĻŋāĻ­āĻ•ā§āϤ- Combinator āĻāĻŦāĻ‚ Attribute selectorāĨ¤ āĻāϗ⧁āϞ⧋ āĻŽā§‹āϟāĻžāĻŽā§āϟāĻŋ āĻĒ⧁āϰ⧋āύ⧋, āĻĒā§āϰāĻžā§Ÿ āϏāĻŦāĻžāχ āϜāĻžāύāĻŋāĨ¤ āφāϰ āĻāχ Attribute selector āϕ⧇ $ ^ ~ * āχāĻ¤ā§āϝāĻžāĻĻāĻŋ āϚāĻŋāĻšā§āύāϗ⧁āϞ⧋ āφāϰāĻ“ āĻļāĻ•ā§āϤāĻŋāĻļāĻžāϞ⧀ āĻ•āϰ⧇āĨ¤ āĻĒ⧁āϰ⧋āύ⧋ āĻšāϞ⧇āĻ“ āĻ…āύ⧇āϕ⧇ āĻāϗ⧁āϞ⧋āϰ āύāĻžāĻŽ āϏāĻŽā§āĻĒāĻ°ā§āϕ⧇ āĻāĻ•āϟ⧁ āĻ•āύāĻĢāĻŋāωāĻļāύ⧇ āĻĨāĻžāϕ⧇āύāĨ¤ āύāĻŋāĻšā§‡āϰ āĻŸā§‡āĻŦāĻŋāϞ⧇ āĻ•āĻŋāϛ⧁ āĻ•āĻŽāύ Combinator āĻāĻŦāĻ‚ Attribute selector āĻĻā§‡ā§ŸāĻž āĻšāϞ⧋, āύāĻžāĻŽ, āĻ­āĻžāĻ°ā§āϏāύ āĻ“ āϏāĻ‚āĻ•ā§āώāĻŋāĻĒā§āϤ āĻĒāϰāĻŋāϚāĻŋāϤāĻŋāϏāĻšāĨ¤


Selector Name Version Description & Example
+ Adjacent Sibling Selector CSS2 Selects the first sibling element immediately following another element.
Example:
ul + p { color: blue; }
~ General Sibling Selector CSS2 Selects all sibling elements that follow another element, not necessarily adjacent.
Example:
ul ~ table { border: 1px solid black; }
[attribute] Attribute Selector CSS1 Selects all elements that have a specific attribute, regardless of its value.
Example:
[class] { color: red; }
[attribute=my-Address] Exact Attribute Value Selector CSS2 Selects elements whose specific attribute exactly matches the value “my-Address”.
Example:
[class=my-Address] { color: green; }
[attribute$=ess] Ends With Attribute Selector CSS2 Selects elements whose attribute ends with a specific string.
Example:
[class$=ess] { color: blue; }
[class|=my] Hyphen-Separated Attribute Selector CSS2 Selects elements whose attribute is either exactly “my” or starts with “my-”, such as “my-address”.
Example:
[class|=my] { color: purple; }
[class^=L] Starts With Attribute Selector CSS2 Selects elements whose attribute starts with the specific value “L”.
Example:
[class^=L] { color: orange; }
[class~=beautiful] Contains Word Attribute Selector CSS2 Selects elements whose attribute contains a specific word (space-separated).
Example:
[class~=beautiful] { color: pink; }
[class*=s] Contains Substring Attribute Selector CSS3 Selects elements whose attribute contains a specific substring anywhere in the value.
Example:
[class*=s] { color: teal; }

āφāϜāϕ⧇ āĻ āĻĒāĻ°ā§āϝāĻ¨ā§āϤāχ, āϏāĻŦāĻžāχ āĻ­āĻžāϞ āĻĨāĻžāĻ•āĻŦ⧇āύ, āφāĻ˛ā§āϞāĻžāĻš āĻšāĻžāĻĢ⧇āϜ :heart:

11 Likes

@RaheelArfeen Take a look here. Very important topic for you.

āĻāϰ āωāĻĻāĻžāĻšāĻžāϰāĻŖ:
HTML

<div class="sample">This is a sample text.</div>
<div class="test">This is a test text.</div>
<div class="example">This is an example text.</div>
 <div class="demo">This text won't be affected.</div>

CSS

[class*="s"] {
    color: teal;
}

āĻāχ āωāĻĻāĻžāĻšāϰāϪ⧇, <div> āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟāϗ⧁āϞ⧋ āϝ⧇āϗ⧁āϞ⧋āϰ āĻ•ā§āϞāĻžāϏ sample, test, āĻāϗ⧁āϞ⧋ āϏāĻŦāϗ⧁āϞ⧋āϤ⧇āχ “s” āĻ…āĻ•ā§āώāϰāϟāĻŋ āφāϛ⧇, āϤāĻžāχ āĻāϗ⧁āϞ⧋āϰ āĻŸā§‡āĻ•ā§āϏāĻŸā§‡āϰ āϰāĻ™ teal āϏ⧇āϟ āĻšāĻŦ⧇āĨ¤

demo,‘example’ āĻāϞāĻŋāĻŽā§‡āĻ¨ā§āϟāϟāĻŋ āĻĒā§āϰāĻ­āĻžāĻŦāĻŋāϤ āĻšāĻŦ⧇ āύāĻž, āĻ•āĻžāϰāĻŖ āĻāϰ āĻ•ā§āϞāĻžāϏ⧇ “s” āύ⧇āχāĨ¤

1 Like

āĻœā§āĻŦā§€ āĻ­āĻžāχ, āĻāϟāĻž āĻŸā§‡āĻŦāĻŋāϞ⧇ āĻĻ⧇āĻ–āĻžāύ⧋ āϏāĻŋāϞ⧇āĻ•ā§āϟāϰāϗ⧁āϞ⧋āϰ āĻŽāĻ§ā§āϝ⧇ āϏāĻŦāĻžāϰ āĻļ⧇āώ⧇ āφāϛ⧇āĨ¤ HTML/CSS āĻāϰ āωāĻĻāĻžāĻšāϰāĻŖāϏāĻš āĻĻ⧇āĻ–āĻžāύ⧋āϰ āϜāĻ¨ā§āϝ āϧāĻ¨ā§āϝāĻŦāĻžāĻĻ :v:

āĻ…āύ⧇āĻ• āĻ…āύ⧇āĻ• āϧāĻ¨ā§āϝāĻŦāĻžāĻĻāĨ¤ āĻŦāĻŋāĻ¸ā§āϤāĻžāϰāĻŋāϤ āϜāĻžāύāϤ⧇ āĻĒāĻžāϰāϞāĻžāĻŽāĨ¤

Onek sundorâ€Ļ Thanks vlo kisu show korar jonno

CSS Pseudo Elements share korar jonno thanks