CSS and Web Styling
Posts, tutorials, and snippets on Cascading Style Sheets (CSS), covering modern layout techniques, responsive design, and best practices for web styling.
Content in CSS
Tutorial:CSS
@scope: Component-Level Style IsolationLimit where selectors match, with donut scopes and proximity.Use CSS @scope to keep component styles inside a root, stop them at a donut-scope limit, and let scope proximity fix nested themes.Snippet:
:playingand:paused: Style Media by Playback StateStyle audio and video players from their playback state.Style audio and video by playback state with CSS :playing, :paused, :buffering and :muted, plus :has() patterns and a JavaScript fallback.Tutorial:The
:openPseudo-Class for<details>,<dialog>and<select>Style anything that opens, selects included, with one pseudo-class.Style the open state of <details>, <dialog> and <select> with the CSS :open pseudo-class. Compare it with [open], :popover-open and :modal, with fallbacks.Tutorial:CSS Custom Highlight API:
::highlight()for Search ResultsHighlight search matches with CSS without touching the DOM.Highlight search results with the CSS Custom Highlight API: ::highlight(), CSS.highlights, StaticRange, priority, accessibility and a mark fallback.Tutorial:
contrast-color(): Automatic Readable Text on Any BackgroundLet CSS choose readable white or black text automatically.Use CSS contrast-color() to pick white or black text for any background colour: how the spec defines it, custom properties and brand colours, buttons and tags, pairing with light-dark(), mid-tone limits, and an @supports fallback.