--netologyBrandColor
with the value purple
for the button
element: button { --netologyBrandColor: purple; }
var
function. With this function, we can tell the browser to take a value from the declared custom property and add it to the inline property.color
, and add a var
function as its value, in the argument of which pass the name of the custom property.border
and color
properties: button { --netologyBrandColor: purple; border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); }
$netologyBrandColor
variable, which stores the main color of the brand: $netologyBrandColor: purple; button { border: 2px solid $netologyBrandColor; color: $netologyBrandColor; }
button { border: 2px solid purple; color: purple; }
--netologyBrandColor
when you hover the mouse over a button. button { --netologyBrandColor: purple; border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); } button:hover { --netologyBrandColor: #27ae60; }
hover
state, the values of the border
and color
properties change. It is because of this feature that user properties are called “live”: they can change directly in the browser, and accordingly change the values of the built-in properties to which they apply.focus
state. button { --netologyBrandColor: #000000; border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); } button:hover { --netologyBrandColor: #27ae60; } button:focus { --netologyBrandColor: #c0392b; outline: 3px solid var(--netologyBrandColor); }
—mq
and —textColor
. Using the first one, we will display the name of the media function on the page, and the second is needed to switch colors. On screens with a width of up to 768px, the text will be purple, and from 769px - red. body::before { content: var(--mq); color: var(--textColor); } @media (max-width: 768px) { body::before { --mq: "max-width: 768px"; --textColor: purple; } } @media (min-width: 769px) { body::before { --mq: "min-width: 769px"; --textColor: red; } }
calc
function, with which you can perform arithmetic operations. It can also work with custom properties. For example, we can control the number of children in a row: .child { width: calc(100% / var(--childCount)); }
--childCount
in the browser, we see the following picture:fill
, stroke
, stroke-width
and others. This can be done in two ways.fill
, stroke
and stroke-width
, to which we will define custom properties as values. <svg class="svg-with-attr" viewBox="0 0 26 28"> <path stroke="var(--iconStroke)" stroke-width="var(--iconStrokeWidth)" fill="var(--iconFill)" d="..."> </svg>
.svg-with-attr{ --iconFill: #eeeeee; --iconStroke: #000000; --iconStrokeWidth: 1px; }
<svg class="svg-with-props" viewBox="0 0 26 28"> <path d="..."> </svg>
.svg-with-props { --iconFill: #ffcc00; --iconStroke: #000000; --iconStrokeWidth: 2px; stroke: var(--iconStroke); stroke-width: var(--iconStrokeWidth); fill: var(--iconFill); }
fill
, stroke
and stroke-width
, so that the difference between the examples was visually noticeable.Source: https://habr.com/ru/post/431616/
All Articles