selectors are very powerful¶
generally speaking, selectors can be combined to create more and more selective ones;
for example
p.class1.class2 {...}
AND: matches elements that are tagged with<p>and have both classesp.class1, p.class2 {...}
OR: will apply to<p>elements that have either one of the classes
pseudo-class selectors¶
pseudo-classes are set by the browser to expose
the status of some elementse.g.
a:hoverallows to match<a>tags
but only when the mouse is hovering above themsimilarly
a:linkmatches<a>tags
that have ahref=attribute (i.e. are real links, not just anchors)
:hover and :link¶
to get it right, we can use the other pseudo-class :link
that is set only on <a> tags that have a href= attribute
rank of element amongst its siblings¶
:first-child,:last-child: pseudo-classes
for what you think they do:nth-child(): can match for example the 4th child,
but also more usefully even/odd ranked
see this page for details
nth-child() example¶
pseudo-class selectors (continued)¶
in particular
:not()for negations
selecting X under Y (optional)¶
div p
matches all <p> elements that are below a <div> element at any depth
div>p
matches all <p> elements that are an immediate child of <div> element
selecting X as a sibling of Y (optional)¶
div + p
matches all <p> elements that are immediate right sibling of a <div> element
div ~ p
matches all <p> elements that are some right sibling of a <div> element
attribute selectors (advanced)¶
HTML elements can have arbitrary attributes,
not justid,class,href, ...it is possible to write selectors that match
on the value of a given attributefor example
a[href="https://www.google.com/"]
would match only the links to google