-
Notifications
You must be signed in to change notification settings - Fork 2
Style
The Style module handles CSS processing and the application of styles to DOM elements. It implements CSS cascade resolution, inheritance, and computes final style values for layout and rendering.
- Parse and organize CSS rules from stylesheets
- Match CSS selectors to DOM elements
- Calculate computed style values using CSS cascade rules
- Handle CSS inheritance and property defaults
- Provide style information to layout and paint stages
The style module implements the CSS cascade algorithm:
- User Agent Styles: Default browser styles
- Author Styles: Styles from website stylesheets
- User Styles: User-defined styles
- Specificity: Higher specificity rules override lower ones
-
Importance:
!importantdeclarations have highest priority - Order: Later rules override earlier ones
CSS specificity is calculated based on:
- ID selectors: Highest weight
- Class selectors and attributes: Medium weight
- Element selectors: Lowest weight
Certain CSS properties automatically inherit from parent elements:
- Text properties: color, font-size, font-family
- Layout properties: Some margin/padding rules
- Visibility: opacity, visibility
Stores computed CSS properties for an element:
- Property values (color, size, position, etc.)
- Computed dimensions and margins
- Font and text properties
- Display and visibility properties
Collection of CSS rules with:
- Selectors identifying target elements
- Property declarations
- Rule specificity information
Values resolved after cascade and inheritance:
- Absolute values (pixels instead of percentages)
- Color specifications (RGB values)
- Font resolution (actual font name and size)
- Collection: Gather all applicable CSS rules
- Matching: Find rules that match the element
- Cascade: Sort rules by specificity and order
- Inheritance: Apply inherited properties from parent
- Defaults: Add default values for unset properties
- Computation: Calculate final values (resolve relative units)
-
Element selectors:
p,div -
Class selectors:
.classname -
ID selectors:
#idname -
Attribute selectors:
[href],[type="text"] -
Descendant selectors:
div p -
Child selectors:
div > p
The module handles various CSS properties:
Display & Layout:
-
display: block, inline, inline-block, flex, grid, none -
position: static, relative, absolute, fixed -
width,height: Sizing properties -
margin,padding: Spacing properties
Text & Font:
-
color: Text color -
font-family: Typeface -
font-size: Text size -
font-weight: Text boldness -
text-align: Text alignment
Appearance:
-
background-color: Background color -
border: Border styling -
opacity: Transparency
Walks the DOM tree to apply styles to each element
Uses computed styles to determine layout algorithms and calculations
Uses style information to render elements with correct appearance
Provides style information through the style API
- Caching of computed styles
- Efficient selector matching
- Lazy evaluation of inherited properties
- Quick lookup of style rules
- Implements CSS cascade as per W3C specifications
- Supports CSS2.1 property set
- CSS3 feature support with extensions
- Proper specificity calculation
- Limited pseudo-class support (
:hover,:active) - No media queries support yet
- No CSS custom properties (variables)
- Animation and transition support pending
- Advanced selectors (
:nth-child,:not()) to be added