Expand description
The cascade, CSS Cascading and Inheritance Level 5, over a Parsec
document: stylesheets from the user agent, the user and the author,
@media and @supports evaluated against an Environment,
@layer, nesting, specificity, !important and style="", then
every element’s computed values with inheritance, the CSS-wide
keywords (revert and revert-layer included), custom properties and
var().
use parsec_css::cascade::Styler;
let doc = parsec::parse(
"<style>@media (min-width: 600px) { p { font-size: 2em } } .x { color: red !important }</style>\
<p class=x style='color: blue'>hi</p>",
false,
);
let styled = Styler::new(Default::default()).with_document_styles(&doc).style(&doc);
let p = parsec::css::SelectorList::parse("p").unwrap().select_first(&doc, doc.root()).unwrap();
assert_eq!(styled.get(p, "color").as_deref(), Some("rgb(255, 0, 0)"));
assert_eq!(styled.get(p, "font-size").as_deref(), Some("32px"));
assert_eq!(styled.get(p, "display").as_deref(), Some("block"));@scope applies with scoping proximity in the cascade order;
@container, and the cq* units, against the sizes
Styler::container_sizes gives;
@import through the fetch Styler::fetch gives, with layer(),
supports() and media; @property registers custom properties, which
then take their syntax, initial value and inheritance from it; and
Styler::at_rules gives the @keyframes, @counter-style and
@property rules that win.
Pseudo-elements are styled too, CSS Pseudo-Elements 4: a rule whose
selector ends in ::before, ::after, ::marker, ::placeholder,
::first-line, ::first-letter, ::selection, ::backdrop,
::file-selector-button or ::highlight() applies to that
pseudo-element of the elements the rest of it matches, and
Styled::get_pseudo gives its computed values, inherited from the
originating element, with only the properties that apply to it
counted, and content worked out. They’re computed when asked for,
not before.
What it doesn’t do is layout: a value that needs boxes to work out,
width: 50% as pixels say, stays as its computed value, and a
container’s size is the caller’s to give.
Structs§
- AtRules
- The
@keyframes,@counter-styleand@propertyrules that win, by name: the last of a name in the cascade’s order, layers counted. - Computed
- One element’s computed values.
- Styled
- Every element’s computed values.
- Styler
- Collects stylesheets and styles documents with them.
Enums§
- Origin
- Where a stylesheet comes from, which decides what wins between them.
- Pseudo
- A pseudo-element the cascade styles.
Constants§
- HTML_
UA_ STYLESHEET - The HTML Standard’s default styles, from its rendering section (§15.3), the parts that don’t need layout or form controls.
Type Aliases§
- Container
Size - A container’s size, width and height in CSS pixels, from the element
and its computed values;
Nonefor one whose size isn’t known. - Fetch
- What an
@import’s URL gives: the stylesheet’s text, orNone.