Skip to content

Commit d7a79ce

Browse files
authored
Implements prefers-contrast media query (#1015)
* Implements prefers-contrast media query This allows users to enable increased contrast in the accessibility settings of their operating system, and see that reflected in the website. This is also a proof-of-concept for implementing this using CSS variables. It requires replacing $ variables (like $primary-color) with CSS variables (var(--primary-color). Benefit is that the CSS variables can dynamically change at runtime (not just during build time). This more dynamic system allows for the prefers contrast color change to only require 8 lines of code. But, this needs some testing to ensure it all works cross-browser. * Adjust the high-contrast color based on feedback
1 parent bc02f69 commit d7a79ce

12 files changed

+77
-64
lines changed

_sass/minima/_article.scss

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ article.guide {
2929
color: white;
3030
line-height: 43px;
3131
text-decoration: none;
32-
background-color: $primary-color;
32+
background-color: var(--link-base-color);
3333
transition: all 150ms $ease;
3434

3535
&:hover {
36-
background-color: darken($primary-color, 5);
36+
background-color: var(--link-hover-color);
3737
}
3838

3939
&.-outline {
4040
background-color: transparent;
41-
color: $primary-color;
42-
border: 1px solid $primary-color;
41+
color: var(--link-base-color);
42+
border: 1px solid var(--link-base-color);
4343

4444
&:hover {
45-
color: darken($primary-color, 5);
46-
border-color: darken($primary-color, 5);
45+
color: var(--link-hover-color);
46+
border-color: var(--link-hover-color);
4747
}
4848
}
4949
}
@@ -133,7 +133,7 @@ article.guide {
133133

134134
&:hover {
135135
.small-video-link__caption {
136-
color: $primary-color;
136+
color: var(--primary-color);
137137
}
138138

139139
.small-video-link__image {
@@ -212,7 +212,7 @@ article.guide {
212212
transition: all 100ms $ease;
213213

214214
&:hover {
215-
color: $primary-color;
215+
color: var(--primary-color);
216216
}
217217
}
218218

_sass/minima/_base.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ main {
7171

7272
a:focus-visible,
7373
button:focus-visible {
74-
outline: 4px solid rgba($primary-color, 0.6);
74+
outline: 4px solid rgba(var(--primary-color-rgb), 0.6);
7575
outline-offset: 1px;
7676
}
7777

@@ -157,16 +157,16 @@ h1 {
157157
* Links
158158
*/
159159
a {
160-
color: $link-base-color;
160+
color: var(--link-base-color);
161161
text-decoration: none;
162162
transition: color 100ms $ease;
163163

164164
&:visited {
165-
color: $link-visited-color;
165+
color: var(--link-visited-color);
166166
}
167167

168168
&:hover {
169-
color: $link-hover-color;
169+
color: var(--link-hover-color);
170170
text-decoration: underline;
171171
}
172172

_sass/minima/_glossary-page.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
color: rgba(var(--front), 0.72);
1515

1616
&:hover {
17-
color: $primary-color;
17+
color: var(--primary-color);
1818
text-decoration: none;
1919
}
2020
}

_sass/minima/_home-banner.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
text-decoration: underline;
203203

204204
&:hover {
205-
color: $primary-color;
205+
color: var(--primary-color);
206206
}
207207
}
208208
}
@@ -222,7 +222,7 @@
222222
text-decoration: underline;
223223

224224
&:hover {
225-
color: $primary-color;
225+
color: var(--primary-color);
226226
}
227227
}
228228

_sass/minima/_nav-list.scss

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545

4646
&.-active {
4747
font-weight: 500;
48-
color: $primary-color;
48+
color: var(--primary-color);
4949
text-decoration: none;
5050

5151
&:visited {
52-
color: $primary-color;
52+
color: var(--primary-color);
5353
}
5454
}
5555

5656
&:hover {
57-
color: $primary-color;
57+
color: var(--primary-color);
5858
}
5959

6060
&:hover,
@@ -77,21 +77,21 @@
7777
svg {
7878
width: 15px;
7979
height: 15px;
80-
color: $link-base-color;
80+
color: var(--link-base-color);
8181
transition: all 150ms $ease;
8282
}
8383

8484
&:active,
8585
&:focus {
8686
border-width: 0;
87-
background-color: rgba($primary-color, 0.1);
87+
background-color: rgba(var(--primary-color-rgb), 0.1);
8888
}
8989

9090
&:hover {
91-
background-color: rgba($primary-color, 0.1);
91+
background-color: rgba(var(--primary-color-rgb), 0.1);
9292

9393
svg {
94-
color: $primary-color;
94+
color: var(--primary-color);
9595
}
9696
}
9797
}
@@ -113,25 +113,25 @@
113113
color: #474747;
114114

115115
&:hover {
116-
color: $primary-color;
116+
color: var(--primary-color);
117117
}
118118
}
119119
}
120120
}
121121

122122
&.-active {
123123
> a.nav-list-link {
124-
color: $primary-color;
124+
color: var(--primary-color);
125125

126126
&:visited {
127-
color: $primary-color;
127+
color: var(--primary-color);
128128
}
129129
}
130130

131131
> .nav-list-expander {
132132
svg {
133133
transform: rotate(90deg);
134-
color: $primary-color;
134+
color: var(--primary-color);
135135
}
136136
}
137137

_sass/minima/_next-previous.scss

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
transition: all 150ms $ease;
2222

2323
&:hover {
24-
color: $primary-color;
24+
color: var(--primary-color);
2525
text-decoration: underline;
2626
}
2727
}
@@ -67,11 +67,11 @@
6767
}
6868

6969
&:hover {
70-
color: $primary-color;
70+
color: var(--primary-color);
7171
text-decoration: none;
7272

7373
svg {
74-
fill: $primary-color !important;
74+
fill: var(--primary-color) !important;
7575
}
7676
}
7777

@@ -119,8 +119,8 @@
119119
}
120120

121121
&:hover {
122-
color: $primary-color;
123-
border-color: $primary-color;
122+
color: var(--primary-color);
123+
border-color: var(--primary-color);
124124
}
125125
}
126126

_sass/minima/_search-page.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
&:active,
2626
&:focus {
27-
border-color: $primary-color;
27+
border-color: var(--primary-color);
2828
outline: none;
2929
}
3030
}
@@ -60,10 +60,10 @@
6060

6161
&:hover {
6262
text-decoration: none;
63-
background-color: rgba($primary-color, 0.05);
63+
background-color: rgba(var(--primary-color-rgb), 0.05);
6464

6565
h3 {
66-
color: $primary-color;
66+
color: var(--primary-color);
6767
}
6868
}
6969
}
@@ -77,4 +77,4 @@
7777
}
7878
}
7979
}
80-
}
80+
}

_sass/minima/_site-footer.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
&:hover {
3333
svg {
34-
color: $primary-color;
34+
color: var(--primary-color);
3535
}
3636
}
3737
}
@@ -51,7 +51,7 @@
5151
font-size: 16px;
5252

5353
&:hover {
54-
color: $primary-color;
54+
color: var(--primary-color);
5555
}
5656
}
5757
}
@@ -74,7 +74,7 @@
7474

7575
&:hover {
7676
svg {
77-
fill: $primary-color !important;
77+
fill: var(--primary-color) !important;
7878
}
7979
}
8080

@@ -101,7 +101,7 @@
101101
font-size: 16px;
102102

103103
&:hover {
104-
color: $primary-color;
104+
color: var(--primary-color);
105105
}
106106
}
107107

_sass/minima/_site-header.scss

+16-16
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
white-space: nowrap;
3333

3434
&:focus {
35-
outline: 2px solid $primary-color;
35+
outline: 2px solid var(--primary-color);
3636
}
3737

3838
svg {
@@ -51,15 +51,15 @@
5151
}
5252

5353
&:focus {
54-
background-color: rgba($primary-color, 0.05);
54+
background-color: rgba(var(--primary-color), 0.05);
5555
}
5656

5757
&:hover {
58-
color: $primary-color;
58+
color: var(--primary-color);
5959
text-decoration: none;
6060

6161
svg {
62-
color: $primary-color;
62+
color: var(--primary-color);
6363
}
6464
}
6565
}
@@ -75,16 +75,16 @@
7575
font-weight: 500;
7676

7777
&:hover {
78-
color: $primary-color;
78+
color: var(--primary-color);
7979
text-decoration: none;
8080
}
8181

8282
&:focus {
83-
background-color: rgba($primary-color, 0.1);
83+
background-color: rgba(var(--primary-color), 0.1);
8484
}
8585

8686
&.active {
87-
color: $primary-color;
87+
color: var(--primary-color);
8888
}
8989
}
9090

@@ -110,18 +110,18 @@
110110
}
111111

112112
&:focus {
113-
background-color: rgba($primary-color, 0.05);
113+
background-color: rgba(var(--primary-color), 0.05);
114114
}
115115

116116
&:hover {
117117
svg {
118-
color: $primary-color;
118+
color: var(--primary-color);
119119
}
120120
}
121121

122122
&.-active {
123123
svg {
124-
color: $primary-color;
124+
color: var(--primary-color);
125125
}
126126
}
127127
}
@@ -205,10 +205,10 @@
205205

206206
&:hover {
207207
text-decoration: none;
208-
background-color: rgba($primary-color, 0.05);
208+
background-color: rgba(var(--primary-color), 0.05);
209209

210210
h3 {
211-
color: $primary-color;
211+
color: var(--primary-color);
212212
}
213213
}
214214
}
@@ -255,11 +255,11 @@
255255
}
256256

257257
&:focus {
258-
background-color: rgba($primary-color, 0.05);
258+
background-color: rgba(var(--primary-color), 0.05);
259259
}
260260

261261
&:hover {
262-
color: $primary-color;
262+
color: var(--primary-color);
263263
}
264264
}
265265

@@ -341,7 +341,7 @@
341341

342342
.nav-trigger {
343343
svg {
344-
fill: $primary-color;
344+
fill: var(--primary-color);
345345
}
346346
}
347347
}
@@ -376,7 +376,7 @@
376376
bottom: -1px;
377377
height: 1px;
378378
opacity: 0;
379-
background-color: $primary-color;
379+
background-color: var(--primary-color);
380380
}
381381

382382
&.active {

0 commit comments

Comments
 (0)