border property will give the same result: button { BORDER: 2px solid #800080; } button { border: 2px solid #800080; } button { --NETOLOGY-BRAND-COLOR: #800080; --netology-brand-color: #27ae60; border: 2px solid var(--NETOLOGY-BRAND-COLOR); color: var(--netology-brand-color); } 
.element::before { --color: rgba(0, 0, 0, 1); --hex: #000000; --value: 20px; --number: 3; --text: "Hey, what's up?"; --keyword: currentColor; } button { --netologyBrandColor: #800080; border-width: 2px; border-style: solid; border-color: var(--netologyBrandColor); } 
button { --netologyBrandColor: #800080; --buttonBorderColor: var(--netologyBrandColor); border-width: 2px; border-style: solid; border-color: var(--buttonBorderColor); } --netologyBrandColor has an incorrect value for the border-color property, such as 18px, the frame will turn black. button { --netologyBrandColor: 18px; --buttonBorderColor: var(--netologyBrandColor); border-width: 2px; border-style: solid; border-color: var(--buttonBorderColor); } 
border-color property, and therefore the browser will set the default value, that is, currentColor . This is very easy to verify by setting the color property to # 800080: button { --netologyBrandColor: 18px; --buttonBorderColor: var(--netologyBrandColor); border-width: 2px; border-style: solid; border-color: var(--buttonBorderColor); color: #800080; } 
border property. button { --netologyBrandColor: 18px; --buttonBorderColor: var(--netologyBrandColor); border: 2px solid var(--buttonBorderColor); color: #800080; } 
border property has a custom property --buttonBorderColor with an incorrect value of 18px as one of the values. According to the described algorithm, the browser simply ignored the border property, so the element disappeared from the frame.var function, we used only one parameter — the name of the custom property. button { --netologyBrandColor: #800080; border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); } button:hover { --netologyBrandColor: #27ae60; } var function can take the second - the default value. To declare the default value, you need to put a comma after the name of the custom property and write the value itself.
--netologyBrandColor . button { border: 2px solid var(--netologyBrandColor, #800080); color: var(--netologyBrandColor, #800080); } button:hover { --netologyBrandColor: #27ae60; } 

var function. In the previous example, the custom property - --netologyBrandColor used twice, respectively, so I set the default value twice.var function allows you to pass another var function, so you can set a different custom property as the default value. I will rewrite the previous example using the custom property --defaultButtonColor : button { --defaultButtonColor: #800080; border: 2px solid var(--netologyBrandColor, var(--defaultButtonColor)); color: var(--netologyBrandColor, var(--defaultButtonColor)); } button:hover { --netologyBrandColor: #27ae60; } --netologyBrandColor inherited from the parent body element. body { --netologyBrandColor: #800080; } button { border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); } </td></tr> 
body element. But if you add the custom property - --netologyBrandColor for the button element, then it will already block the property from the body element. body { --netologyBrandColor: #800080; } button { --netologyBrandColor: #27ae60; border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); } 
--netologyBrandColor at the button element overrides the property - --netologyBrandColor , which we specified for the body element.root , which allows you to specify custom properties that apply to the root element of the document. For example, in the HTML document for the html element. :root { --netologyBrandColor: #800080; } button { border: 2px solid var(--netologyBrandColor); color: var(--netologyBrandColor); } 
root pseudo- root works in SVG documents. For example, I will declare custom properties in the style tag. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 28" width="50" height="50"> <style> :root{ --iconColor: #ffcc00; --iconStroke: #000000; --iconStrokeWidth: 2px; } </style> <path stroke="var(--iconStroke)" stroke-width="var(--iconStrokeWidth)" fill="var(--iconColor)" d="M26 10.109c0 .281-.203.547-.406.75l-5.672 5.531 1.344 7.812c.016.109.016.203.016.313 0 .406-.187.781-.641.781a1.27 1.27 0 0 1-.625-.187L13 21.422l-7.016 3.687c-.203.109-.406.187-.625.187-.453 0-.656-.375-.656-.781 0-.109.016-.203.031-.313l1.344-7.812L.39 10.859c-.187-.203-.391-.469-.391-.75 0-.469.484-.656.875-.719l7.844-1.141 3.516-7.109c.141-.297.406-.641.766-.641s.625.344.766.641l3.516 7.109 7.844 1.141c.375.063.875.25.875.719z"/> </svg> 
root . Accordingly, this proves that the pseudo-class root applies not only to the html tag, but to any root element.Source: https://habr.com/ru/post/435654/
All Articles