mirror of
https://github.com/wahyd4/knowledge.git
synced 2026-08-09 13:15:52 +10:00
Add css variables
This commit is contained in:
+40
-3
@@ -103,12 +103,14 @@ How browser render web page
|
||||
The flow diagram when you access a website
|
||||
|
||||

|
||||
|
||||
# CSS
|
||||
|
||||
- tips
|
||||
## tips
|
||||
|
||||
- inline element can’t set width, modify the display to inline-block
|
||||
- inline element
|
||||
* inline element can’t set width, modify the display to inline-block
|
||||
|
||||
## inline element
|
||||
* i
|
||||
* span
|
||||
* a
|
||||
@@ -118,3 +120,38 @@ The flow diagram when you access a website
|
||||
* button
|
||||
* textarea
|
||||
* br
|
||||
|
||||
## CSS custom properties(variables)
|
||||
|
||||
```css
|
||||
# global variable
|
||||
:root {
|
||||
font-size: 16px;
|
||||
}
|
||||
element {
|
||||
--main-bg-color: brown;
|
||||
}
|
||||
```
|
||||
Then you use it like:
|
||||
|
||||
```css
|
||||
element {
|
||||
background-color: var(--main-bg-color);
|
||||
}
|
||||
```
|
||||
|
||||
Some advanced usage, you can have default value when variable is not set
|
||||
|
||||
```css
|
||||
.two {
|
||||
color: var(--my-var, red); /* Red if --my-var is not defined */
|
||||
}
|
||||
|
||||
.three {
|
||||
background-color: var(--my-var, var(--my-background, pink)); /* pink if my-var and --my-background are not defined */
|
||||
}
|
||||
|
||||
.three {
|
||||
background-color: var(--my-var, --my-background, pink); /* Invalid: "--my-background, pink" */
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user