pub struct Global { /* private fields */ }Expand description
Rules for elements by their tag, and the fonts the page loads.
The rules sit in BASE_LAYER, before the classes of
Styles, so an element’s own style overrides them. Conditions in a
rule’s style apply to the selector as they do to a class.
use hypersig_style::value::{Color, FontFamily, rem};
use hypersig_style::{Element, Global, PseudoClass, Style};
let global = Global::preflight()
.rule(Element::Body, Style::new().font_family(FontFamily::SystemUi))
.rule(
Element::A,
Style::new().color(Color::CRIMSON).on(PseudoClass::Hover, Style::new().color(Color::RED)),
);
let css = global.to_css();
assert!(css.contains("body{font-family:system-ui;line-height:1.5}"));
assert!(css.contains("a:hover{color:red}"));Implementations§
Source§impl Global
impl Global
Sourcepub fn preflight() -> Self
pub fn preflight() -> Self
A small reset: border-box sizing everywhere, no default margins,
form controls in the page’s font, and media that shrinks to its box.
Sourcepub fn rule(self, selector: impl Into<Selector>, style: Style) -> Self
pub fn rule(self, selector: impl Into<Selector>, style: Style) -> Self
Adds style for every element selector matches. A later rule for the
same selector adds to the earlier one, and wins where both set a
property under the same conditions.
Sourcepub fn merge(self, global: Self) -> Self
pub fn merge(self, global: Self) -> Self
Adds the rules and fonts of global, whose rules win over this one’s.
Sourcepub fn to_css(&self) -> String
pub fn to_css(&self) -> String
The rules in BASE_LAYER, then the @font-face rules.
§Panics
Panics if a rule’s style uses a pseudo-element with
Selector::Everything, which already names ::before and
::after, or a Condition::Group or
Condition::Peer, which need a marked
element the selector does not name.