Selector (CSS)
A CSS selector is the part of a CSS rule that describes what elements in a document the rule will match. The matching elements will have the rule's specified style applied to them.
Example
Consider this CSS:
p {
color: green;
}
div.warning {
width: 100%;
border: 2px solid yellow;
color: white;
background-color: darkred;
padding: 0.8em 0.8em 0.6em;
}
#customized {
font:
16px Lucida Grande,
Arial,
Helvetica,
sans-serif;
}
The selectors here are We can then apply this CSS to some HTML, such as: This is happy text. This is happy text. The resulting page content is styled like this: Learn more about CSS selectors in our introduction to CSS. Basic selectors Grouping selectors Combinators Pseudo"p"
(which applies the color green to the text inside any element),
"div.warning"
(which makes any "warning"
look like a warning box), and "#customized"
, which sets the base font of the element with the ID "customized"
to 16-pixel tall Lucida Grande or one of a few fallback fonts.
See also
elementname
.classname
#idname
* ns|* *|*
[attr=value]
a:active, a:visited
A, B
A + B
A ~ B
A > B
A B