-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadv-calc-variables-combined.html
93 lines (82 loc) · 2.74 KB
/
adv-calc-variables-combined.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Combining CSS Calc and Variables</title>
<style>
* {
box-sizing: border-box;
}
/* set the global variables for hsl */
.btn {
--background-hue: 0;
--background-saturation: 0%;
--initial-background-lightness: 90%;
--background-lightness: var(--initial-background-lightness);
--border-lightness: calc(var(--initial-background-lightness) - 20%);
background-color: hsl(var(--background-hue), var(--background-saturation), var(--background-lightness));
border: 1px solid hsl(var(--background-hue), var(--background-saturation), var(--border-lightness));
outline: none;
cursor: pointer;
padding: 0.5em 1em;
border-radius: 0.3em;
}
.btn:hover,
.btn:focus {
--background-lightness: calc(var(--initial-background-lightness) - 10%);
box-shadow: 0 0 5px 0 hsl(var(--background-hue), var(--background-saturation), var(--border-lightness));
}
.btn.btn-primary {
/* leverage the css variables to set hsl values only */
--background-hue: 271;
--background-saturation: 70%;
--initial-background-lightness: 50%;
color: white;
}
.btn.btn-accent {
--background-hue: 200;
--background-saturation: 100%;
--initial-background-lightness: 40%;
color: white;
}
.btn.btn-danger {
--background-hue: 0;
--background-saturation: 60%;
--initial-background-lightness: 50%;
color: white;
}
.btn.btn-large {
font-size: 1.25rem;
}
.btn.btn-small {
font-size: 0.75rem;
}
.btn.btn-pill {
border-radius: 1000000px;
}
.btn.btn-custom {
background: linear-gradient(to right, hsl(271, 70%, 50%), hsl(200, 100%, 40%));
color: white;
border-color: #222;
}
.btn.btn-custom:hover,
.btn.btn-custom:focus {
background: linear-gradient(to right, hsl(271, 70%, 40%), hsl(200, 100%, 30%));
border-color: black;
box-shadow: 0 0 5px 0 black;
}
</style>
</head>
<body>
<button class="btn">Default</button>
<button class="btn btn-primary">Primary</button>
<button class="btn btn-accent">Accent</button>
<button class="btn btn-danger">Danger</button>
<button class="btn btn-large">Large</button>
<button class="btn btn-small">Small</button>
<button class="btn btn-pill">Pill</button>
<button class="btn btn-custom">Custom</button>
</body>
</html>