CSS Selectors
Define the elements to which a set of CSS rules apply
Basic Selectors | Syntax | Definition | Example |
---|---|---|---|
Universal selector | * | Selects all elements. Optionally, it may be restricted to a specific namespace or to all namespaces |
* { color: blue; } |
Type selector | elementname | Selects all elements that have the given node name |
section { color: red; } |
Class selector | .classname | Selects all elements that have the given class attribute |
.index { color: yellow; } |
ID selector | #idname | Selects an element based on the value of its id attribute. There should be only one element with a given ID in a document. |
#large-title { color: green; } |
Attribute selector | [attr] | Selects all elements that have the given attribute |
[href] { color: purple; } |