CSS is Logical

  • Documents flow in the direction of the writing mode.
  • Elements flow in block and inline directions.
  • The block and inline directions are based on the writing mode.
  • Relatively positioned elements have a reserved space in the document flow while absolutely positioned elements are pulled out of it.
  • Screens are measured in viewport units.
  • Parent elements are measured in container units.
  • Em and rem units evaluate relative to their elemental and root contexts.
  • Setting z-index creates a new stacking context for managing the way elements visually overlap one another.
  • The Cascade organizes selectors in prioritized layers that can be re-organized into customized Cascade Layers.
  • Selectors are evaluated by a specificity score.
  • The applied style when two selectors match is the one that appears lowest in the Cascade when they share the same origin.
  • If one property is invalid, the next matched property in a matching selector is used.
  • width looks up the tree while height looks down the tree.
  • Specific properties can be declared based on whether or not a browser @supports it.
  • An element can be selected if it :is() a certain selector, is :not() a certain selector, :has() another element, or :where() it meets a certain condition.

CSS be weird, but it not be illogical.

✏️ Handwritten by Geoff Graham on February 7, 2024

29 Comments

  1. # February 7, 2024

    @geoff I love this! It’s totally possible to have a good, logical mental model for CSS. I’d add to the list that styles in the Shadow DOM fit into a logical mental model of CSS.

    Reply
  2. # February 9, 2024

    “Height looks down the tree” is misleading. It’s more accurate to say that block elements are, by default, intrinsically sized in height and extrinsically sized in width.

    Reply
  3. Anonymous
    # February 11, 2024

    Another item worth of note for me is that among the selectors with the same specificity, selectors declared later in the CSS file overrides selectors declared earlier, regardless of the order of the selector used in the HTML file.

    Reply
  4. N
    # February 11, 2024

    CSS is fun when it works the way you want

    Reply
  5. Jewels
    # February 17, 2024

    These are some helpful little tidbits! I might save this site for the next time I am helping someone learn CSS!

    Reply

Leave a Reply

Markdown supported