Variable

Variable

Can I use ?Can I use ?
classproperties
$key:value--key: value

Overview

CSS variables are entities defined by CSS authors that contain specific values to be reused throughout a document.
Custom properties are subject to the cascade and inherit their value from their parent.
This virtual variable style will make Shadow DOM responsive and customizable in style.

<div class="">
.\$size\:2\.5rem {
    --size: 2.5rem
}

Basic usage

Stylize a shadow dom

Let's say this's your custom element and its tree:

<test-element>
    ▼ #shadow-root (open)
      <button part="button"></button>
</test-element>

and the element contains an encapsulated style like this:

:host {
    --button-bg: red;
}

[part=button] {
    background: var(--button-bg);
}

Elements in the shadow DOM cannot be selected via descendant selectors, but you can:

<test-element class="$button-bg:red $button-bg:pink@sm">
    ▼ #shadow-root (open)
      <button part="button"></button>
</test-element>

Applying with functions

<div class="$size:$(custom-size)">...</div>

Master supports native CSS variables and functions, just add var(--key) or use shorthand$(key) for variables.

You can also use calc(expression), env(expression) and other CSS functions if the property supports it.

To learn more, see the Functions documentation.

Conditionally apply

States and selectors

<div class="$size:2.5rem:hover">...</div>

Master supports all native CSS selectors, just add :hover, :disabled, chaining, combinators and other CSS selectors as usual.

To learn more, see the Selectors documentation.

Responsive breakpoints

<div class="$size:2.5rem@sm">...</div>

Responsive breakpoints can be applied to all styles. Some available breakpoints are 3xs, 2xs, xs, sm,md, lg, xl, 2xl, 3xl, 4xl. Arbitrary breakpoints can be specified through comparison operators >, >=, <, <=.

To learn more, see the Breakpoints documentation.

<div class="$size:2.5rem@print">...</div>

Master supports media types like print, screen, speech, all, and other media queries.

To learn more, see the Media Queries documentation.

Dark mode and color schemes

<div class="$size:2.5rem@dark">...</div>

Master uses the selector html.dark to support color schemes. Now, you can easily fine-tune your style for the color schemes.

To learn more, see the Color Schemes documentation.


© Aoyue Design LLC.
關於此頁的問題
編輯自AronLola