CSS - Selectors / Selektoren: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
 
(6 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
== Links ==
 
== Links ==
Gute Übersicht mit Bildern: https://www.mediaevent.de/css/css-selektor-kontextselektor.html
+
Gute Übersicht mit Bildern: https://www.mediaevent.de/css/css-selektor-kontextselektor.html
 +
https://learn.shayhowe.com/advanced-html-css/complex-selectors/
 
== Arten von Selektoren ==
 
== Arten von Selektoren ==
 
=== Nachfahre / Descendant Selector ===
 
=== Nachfahre / Descendant Selector ===
Zeile 45: Zeile 46:
 
ul
 
ul
 
p
 
p
 +
</pre>
 +
 +
=== Attribute Selektieren ===
 +
 +
 +
{| class="wikitable"
 +
|-
 +
! Selektor !! Name !! Verwendung
 +
|-
 +
| a[target] || Attribute Present Selector || Selects an element if the given attribute is present
 +
|-
 +
| a[href="http://google.com/"] || Attribute Equals Selector || Selects an element if the given attribute value exactly matches the value stated
 +
|-
 +
| a[href*="login"] ||Attribute Contains Selector ||S elects an element if the given attribute value contains at least once instance of the value stated
 +
|-
 +
| a[href^="https://"] ||Attribute Begins With Selector || Selects an element if the given attribute value begins with the value stated
 +
|-
 +
| a[href$=".pdf"] ||Attribute Ends With Selector || Selects an element if the given attribute value ends with the value stated
 +
|-
 +
| a[rel~="tag"] || Attribute Spaced Selector || Selects an element if the given attribute value is whitespace-separated with one word being exactly as stated
 +
|-
 +
| a[lang[barzeichen]="en"] || Attribute Hyphenated Selector || Selects an element if the given attribute value is hyphen-separated and begins with the word stated
 +
|-
 +
|}
 +
 +
Beispiel:
 +
<pre>
 +
a[href$=".pdf"] {
 +
  background-image: url("images/pdf.png");
 +
}
 
</pre>
 
</pre>
  
 
== CSS3 Pseudo Selektoren ==
 
== CSS3 Pseudo Selektoren ==
 
https://www.mediaevent.de/css/css3-selektor-pseudo.html
 
https://www.mediaevent.de/css/css3-selektor-pseudo.html

Aktuelle Version vom 12. August 2022, 15:47 Uhr

Links[Bearbeiten]

Gute Übersicht mit Bildern: https://www.mediaevent.de/css/css-selektor-kontextselektor.html
https://learn.shayhowe.com/advanced-html-css/complex-selectors/

Arten von Selektoren[Bearbeiten]

Nachfahre / Descendant Selector[Bearbeiten]

Inneres Element muß aber nicht direkt folgen

div p
div
--span
----p

Kind / Child Selector[Bearbeiten]

Inneres Element muß direktes Kind sein, also kein Enkel. Muß aber nicht direkt im Code folgen.

div>table
div
--p
--table
aber nicht
div
--span
----table

Nachbar / Adjacent Selector[Bearbeiten]

Muß direkt folgen

h5+p
h5
p
aber nicht
h5
span
p

Indirekter Nachbar[Bearbeiten]

Alle folgenden

h5~p
h5
p
ul
p

Attribute Selektieren[Bearbeiten]

Selektor Name Verwendung
a[target] Attribute Present Selector Selects an element if the given attribute is present
a[href="http://google.com/"] Attribute Equals Selector Selects an element if the given attribute value exactly matches the value stated
a[href*="login"] Attribute Contains Selector S elects an element if the given attribute value contains at least once instance of the value stated
a[href^="https://"] Attribute Begins With Selector Selects an element if the given attribute value begins with the value stated
a[href$=".pdf"] Attribute Ends With Selector Selects an element if the given attribute value ends with the value stated
a[rel~="tag"] Attribute Spaced Selector Selects an element if the given attribute value is whitespace-separated with one word being exactly as stated
a[lang[barzeichen]="en"] Attribute Hyphenated Selector Selects an element if the given attribute value is hyphen-separated and begins with the word stated

Beispiel:

a[href$=".pdf"] {
  background-image: url("images/pdf.png");
}

CSS3 Pseudo Selektoren[Bearbeiten]

https://www.mediaevent.de/css/css3-selektor-pseudo.html