20 CSS functions Flashcards

1
Q

calculate 20 + 12 in CSS

A

calc(20 + 12)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ds f

A

s df

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does min() work?

A

min(100px, 100%)
It takes the smallest of the numbers

can do math inside min
min(100px + 20px, 100vw - 2rem)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does max() work?

A

max(100px, 4em, 50%)

from the list of given values, it will take the largest one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

set a CSS variable (custom property)

call a CSS variable

A

–variable-name: value

var(–variable-name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does CSS custom property scope work?

A

scope includes the selector the custom property was declared for as well as any descendants of that selector.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you make a css variable available to all selectors?

A

make the variable in :root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Using root properties, how do you set a light or dark theme?

A

In CSS
Select :root.lighttheme and :root.darktheme that use the set the same variable names

These variable names will be used throughout the document’s other elements.

In JS
create a function that sets the classname to only lighttheme or darktheme on a click

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Inheret the theme properties from the os

What are some drawbacks (2)

A

To set the theme to dark if the user has set the theme to dark:
@media (prefers-color-scheme: dark) {
:root {
–border-btn: 1px solid rgb(220, 220, 220);
–color-base-bg: rgb(18, 18, 18);
–color-base-text: rgb(240, 240, 240);
–color-btn-bg: rgb(36, 36, 36);
–theme-name: “dark”;
}
}

To set the theme to lightif the user has set the theme to light:
@media (prefers-color-scheme: light)
1. only light and dark
2. Doesn’t (by itself) allow user to change it on their own

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Have a fallback option within a css variable

A

var(option1, backupoptions)

it can be another var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens if the variable is set to something invalid vs when it’s not a variable?

p {
color: blue;
}

p {
color: 16px;
}

VS

:root {
–text-color: 16px;
}

p {
color: blue;
}

p {
color: var(–text-color);
}

A

In the first instance, p is blue

in the second, p is black (the default initial colour)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

refer to a variable in JS (card needs work)

A
// get variable from inline style
element.style.getPropertyValue("--my-var");
// get variable from wherever
getComputedStyle(element).getPropertyValue("--my-var");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

ds

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly