CSS Style Selector Reference
Table of contents
Overview
A style selector contains one or more style properties and defines a set of conditions that an element must match in order to have any properties applied to it. A rule contains one or more selectors and defines a condition that the current environment must meet to have the selectors considered.
The library supports the use of a sub-set of all the current CSS selectors and at-rules. These are detailed below.
/* A simple selector matching all div elements */
div {
color: red;
}
/* A simple selector matching all elements tagged with the 'blue' class */
.blue {
color: blue;
}
/* Adds a border and padding to all blue tagged divs */
div.blue{
border: solid 1pt blue;
padding: 5pt;
}
@media print{
/* All styles within this rule will be applied by the library */
div {
color: black;
}
}
For more information on selectors see the Using Styles articles.
Unsupported Rules
If the library encounters a css rule it cannot understand the entire content of that rule will be skipped.
@scope (.article-body) to (figure) {
/* Nothing after this will be checked
img {
border: 5px solid black;
background-color: goldenrod;
}
*/
}
.next{
/* This will be included */
color: red;
}
Unsupported Selectors
If the library encounters a css selector it cannot understand, then it will be skipped. But any valid selectors will be maintained.
.myclass[lang="pt"] {
/* Nothing after this will be checked.
img {
border: 5px solid black;
background-color: goldenrod;
*/
}
.next{
/* This will be included */
color: red;
}
Combining Selectors
If the library encounters an individual css selector within a selector list, that it cannot understand, then it will be skipped. But any valid selectors will be maintained.
.myclass[lang="pt"], .next {
/* This will be included for .next */
color: red;
}
Selector Reference
The library supports the use of the following selectors and rules, sorted by category.
Style Selectors
The following selectors are supported in the library.
| Selector | Example | Description |
|---|---|---|
| Class Name | .name | Will match against any element that has that class name associated with it, and apply the style properties. |
| Element ID | #id | Will match against an element that has that identifier, and apply the style properties. |
| ELement Name | div | Will match against any element that has that is that element, and apply the style properties. |
| Document Root | :root | Sets the default properties, or CSS variable values for that document to use during processing. |
| Catch All | * | Matches all elements and applies the style properties. Can be used in combination with another selector to reduce the scope. |
Style Combinators
Combinators allow mutiple selectors to be combined into a single match check. The following combinators are supported in the library .
| Combinator | Character | Description |
|---|---|---|
| Descendant | space (“ “) | Whitespace between one selector and the next will match elements on the last selector that have any parent(s) in the hierarchy that match the preceeding selector(s). |
| Direct Child | > | A greater-than symbol (>) between one selector and the next will match elements on the last selector that have direct parent(s) in the hierarchy that match the preceeding selector(s). |
| Selector List | comma (“, “) | A comma between one selector and the next will make a list of selectors and match on any of the selectors present. |
Style Rules Reference
| Rule Namme | Example | Description |
|---|---|---|
| Media Rule | @media | The media rule groups styles that are most appropriate for a display device. Most specifically the library will only use styles with a ‘print’ media query within it’s list. |
| Page Size Rule | @page | The page rule allows modification of the page paper sizing, along with margins on that page. They can be named to be applied to individual sections of the resultant document. |
| Font Face Rule | @font-face | The font-face rule defines a custom font available to be used from a local or remote source along with the format it uses. See Using Fonts for more information on font support. |
| Counter Style Rule | @counter-style | The counter style rule defines a custom counter available to be refererences from a list-style-type or a css counter instruction. See Using Counters for more information. |
Style Pseudo-Element Reference
Pseudo element are keywords added to a selector to identify particular parts of a matching element
| Name | Example | Description |
|---|---|---|
| Before Content | ::before | ::before creates new pseudo element that is the first child of the matched element, often used to add cosmetic content. Also supports counters |
| After Content | ::after | ::after in a style selector creates new pseudo element that is the last child of the matched element, often used to add cosmetic content. Also supports counters |