📰 IT NachrichtenLinkdump 37/2026(11.09.2026 um 11:42 Uhr)
📰 IT NachrichtenDie große Ratlosigkeit – Wie geht es weiter in der CDU?(11.09.2026 um 13:29 Uhr)
📰 IT NachrichtenWüst und die CDU im Wind der Brandmauer-Debatte(11.09.2026 um 14:47 Uhr)
🔧 AI Nachrichten KI-Angriffe: Geheimdienste sollen neue Befugnisse erhalten(11.09.2026 um 11:00 Uhr)
📰 IT NachrichtenKI-Hack: Anthropic muss nächsten Vorfall mit Claude offenlegen(11.09.2026 um 16:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🐧 Linux TippsPACMAN: KI-Framework steuert Fusionsplasma in Echtzeit(11.09.2026 um 10:46 Uhr)
📰 IT NachrichtenLinkdump 37/2026(11.09.2026 um 11:42 Uhr)
📰 IT NachrichtenDie große Ratlosigkeit – Wie geht es weiter in der CDU?(11.09.2026 um 13:29 Uhr)
📰 IT NachrichtenWüst und die CDU im Wind der Brandmauer-Debatte(11.09.2026 um 14:47 Uhr)
🔧 AI Nachrichten KI-Angriffe: Geheimdienste sollen neue Befugnisse erhalten(11.09.2026 um 11:00 Uhr)
📰 IT NachrichtenKI-Hack: Anthropic muss nächsten Vorfall mit Claude offenlegen(11.09.2026 um 16:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🐧 Linux TippsPACMAN: KI-Framework steuert Fusionsplasma in Echtzeit(11.09.2026 um 10:46 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 5 Min Lesezeit
0

Selectors in CSS

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Introduction



Selector is the first part of any CSS rule. The selector identifies to which part or section of the HTML document the rule will be applied.




CODE
    selector {
property: value;
....
}






The rule is enclosed in { }. A rule allows us to specify on or more properties and their values that decides how it will render.






Simple Selectors



Select elements based on name, id, class






name of element



The name of the element is directly used as the selector.



eg




CODE
    body {
...
}
div {
...
}
input {
...
}









id of element



In HTML, some elements can be identified with the id attribute.




CODE
    <p id='idname'>This is a some text.</p>






In CSS, the selector for this will start with a hash (#) followed by the name of the id.



eg




CODE
    #idname {
...
}









class of element



In HTML, when you may define a class attribute.




CODE
    <div class='container'>...</div>






In CSS, the selector for the class starts with a period (.) followed by the name of the class.




CODE
    .container {
...
}






Multiple class names can be marked in HTML by seperating them with a space.




CODE
    <div class='card card-info'>






When multiple classes are defined, then the styling rules will apply in the order they are listed. The latest value for a property will prevail if the property values are given in more than one class.






Attribute Selector



Attribute selector matches elements based on the value of some of its attribute.




  • [attr]

  • [attr=value]

  • [attr~=value]

  • [attr|=value]

  • [attr^=value]

  • [attr$=value]

  • [attr*=value]

  • [attr operator value i]

  • [attr operator value s]



. and # are special operators to identify the attributes id and class. [] allow to select any attribute.



Some examples...

| selector | description |

|-|-|

| a[target] | any element a having a target attribute |

| a[target='_blank'] | any anchor element having target = _blank |

| div[class\|="card"] | any div with class having value the whole word card or card followed by -, like card-head or card-body |

| div[class^="card"] | any div with class whose value starts with card |

| div[class$="head"] | any div with class whose value ends with head |

| div[class*="card"] | any div with class having value contains the string card anywhere |





Selector List - Comma (,) separated





CODE
    div, li, .card-info {
...
}





If the same styling is to be applied to multiple selectors then use comma (,) to separate the selectors and then define the css rule.





Combinators



A combinator is a combination of two or more selectors used together. Combinators are used define the specificity of the selector.





Descendant Selector (space)



eg




CODE
    div p {
...
}






This will select all ps under all divs. ps in any child of the divs will also be included.






Child Selector (>)



eg




CODE
    div > p {
...
}






This will select all ps directly under all divs. ps nested inside any child of div will not be included.






Adjacent Sibling Selector (+)



eg




CODE
    div + p {
...
}






This will select ps that are immediately after divs - at the same level. No parent or child will be included.






General Sibling Selector (~)



eg




CODE
    div ~ p {
...
}






This will select ps that are anywhere after divs - at the same level. No parent or child will be included.






Nested Selector (with and without &)






preceding selector with &






CODE
    .parent {
...
& :nested {
...
}
}






evaluates to...




CODE
    .parent {
... parent rules
}

.parent:nested {
...child rules
}






all .parent having puesdo-class :nested






without &



When the selector is nested without &, a space is added to the resulting nested css-rule, i.e.




CODE
    .parent {
... parent rules
:nested {
... child rules
}
}






evaluates to...




CODE
    .parent {
... parent rules
}

.parent *:nested {
...child rules
}






all descendants of .parent having puesdo-class :nested






adding & after the selector






CODE
    .outer {
... outer rules
.nested & {
...nested rules
}
}







evaluates to...




CODE
    .outer {
... outer rules
}

.nested .outer {
...nested rules
}






Here outer rules will apply normally apply .outer selector, but when .outer is a descendant of the .nested selector then the nested rules will apply.






adding multiple & after the selector






CODE
    .parent {
... parent rules
.nested & & & {
...nested rules
}
}







the three &s evaluate to...




CODE
    .parent {
... parent rules
}

.nested .parent .parent .parent {
...child rules
}









Pseudo-classes



Pseudo-classes are selectors that are recognized in the browser without explicitly being defined in the web-page.



A pseudo-class can used by adding : before it.



eg




CODE
  a:active          /* active links */
div:hover /* when mouse hovers over the <div> */
div:first-child /* the first child inside the <div> */









List of Pseudo-classes




  • :active

  • :any-link

  • :dir

  • :empty


  • :has(selector)

  • :hover


  • :is(selector)


  • :lang(language)

  • :link


  • :not(selector)

  • :root


  • :state(identifier)

  • :target

  • :visited


  • :where(selector)



for child




  • :first-child

  • :last-child


  • :nth-child(position)


  • :nth-last-child(position)

  • :only-child



for of-type




  • :first-of-type

  • :last-of-type


  • :nth-of-type(position)


  • :nth-last-of-type(position)

  • :only-of-type



for inputs




  • :checked

  • :disabled

  • :enabled

  • :focus

  • :focus-visible

  • :in-range

  • :inderminate

  • :invalid

  • :optional

  • :out-of-range

  • :read-only

  • :read-write

  • :required

  • :valid






CSS Pseudo Elements



Pseudo Elements do not have to be defined in the web-page, yet the browser recognizes these elements.






List of pseudo elements




  • ::after

  • ::before

  • ::file-selector-button

  • ::first-letter

  • ::first-line

  • ::grammar-error

  • ::marker

  • ::placeholder

  • ::selection

  • ::spelling-error

  • ::target-text

  • ::backdrop

  • ::cue

  • ::highlight

  • ::part

  • ::slotted

  • ::view-transition

  • ::view-transition-image-pair()

  • ::view-transition-group()

  • ::view-transition-new()

  • ::view-transition-old()



I hope you find this useful.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
290 Euro sparen: Lidl bietet beliebten Kaffeevollautomaten zum Sparpreis an
1 Quelle
Linkdump 37/2026
1 Quelle
Die große Ratlosigkeit – Wie geht es weiter in der CDU?
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Selectors in CSS

Thematisch verwandte Begriffe: Selectors · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...