Pingu
Computer MySQL PostgreSQL Books Publications
Spielereien Kanu Geopolitik Business TopoDB POI Klettersteigen History TransPool Thermal Baden Brokenstuben Goldwaschen
Blog Contact
Shinguz
Google
/ch/open

Meine CSS Notizen

/ home / computer

Table of Contents

Details

Simple selectors

Selector Description Example
p {...} Element type selector <p></p>
#para {...} id selector <span id="para"></span>
.center {...} class selector <span class="center"></p>
p.center {...} Only specific elements affected by class selector <p class="center"></p>
2 Classes (and) <p class="center larger"></p>
* {...} Universal selector Every element on the page.
h1, h2, p {...} Group selector Group selectors for elements h1, h2 and p

Child selectors

Select elements that fall within on another.

Selector Description Example
article h2 {...} Descendant selectors (inheritance) <h2>...</h2><article><h2>selected</h2><div><h2>selected</h2></div></article>
article > p {...} Direct child selectors (no inheritance) <p>...</p><article><p>selected</p><div><p>...</p></div></article>

Sibling Selectors

The general sibling selector allow elements to be selected based on their sibling elements, those which share the same common parent. The first element identifies what the second element shall be a sibling with, and both of which must share the same parent.

Selector Description Example
h2 ~ p {...} General Sibling Selector <p>...</p><section><p>...</p><h2>...</h2><p>elected</p><div><p>...</p></div><p>selected</p></section>
h2 + p {...} Adjacent Sibling Selector <p>...</p><section><p>...</p><h2>...</h2><p>selected</p><div><p>...</p></div><p>...</p></section>

Attribute Selectors

Selector Description Example
a[target] {...} Attribute Present Selector <a href="#" target="_blank">...</a>
a[href="https://example.org/"] {...} Attribute Equals Selector <a href="https://example.org/">...</a>
a[href*="login"] {...} Attribute Contains Selector <a href="/login.php">...</a>
a[href^="https://"] {...} Attribute Begins With Selector <a href="https://example.org/">...</a>
a[href$=".pdf"] {...} Attribute Ends With Selector <a href="/docs/menu.pdf">...</a>
a[rel~="tag"] {...} Attribute Spaced Selector <a href="#" rel="tag nofollow">...</a>
a[lang|="en"] {...} Attribute Hyphenated Selector <a href="#" lang="en-US">...</a>

Pseudo-classes

Pseudo-class Description Example
a:link {...} Link Pseudo-classes
a:visited {...}
a:hover {...} User Action Pseudo-classes
a:active {...}
a:focus {...}
input:enabled {...} User Interface State Pseudo-classes
input:disabled {...}
input:checked {...}
input:indeterminate {...}
li:first-child {...} Structural & Position Pseudo-classes
li:last-child {...}
div:only-child {...}
p:first-of-type {...}
p:last-of-type {...}
img:only-of-type {...}
li:nth-child(3n) {...}
section:target {...} Target Pseudo-class <section id="hello">...</section>
div:empty {...} Empty Pseudo-class

Pseudo-elements

…

Sources