Add fallbacks to CSS variables for older browsers

This commit is contained in:
Danila Fedorin 2023-03-11 14:07:43 -08:00
parent c631be65bc
commit 0bd55bc58a
7 changed files with 71 additions and 61 deletions

View File

@ -1,21 +1,5 @@
@import "variables.scss";
$code-color-lineno: grey;
:root {
--code-color-keyword: black;
--code-color-type: black;
--code-color-comment: grey;
}
@media (prefers-color-scheme: dark) {
:root {
--code-color-keyword: #{darken(white, 40%)};
--code-color-type: #{darken(white, 40%)};
--code-color-comment: grey;
}
}
.highlight-label {
padding: 0.25rem 0.5rem 0.25rem 0.5rem;
border: $code-border;
@ -32,7 +16,7 @@ $code-color-lineno: grey;
code {
font-family: $font-code;
background-color: var(--code-color);
@include var(background-color, code-color);
border: $code-border;
padding: 0 0.25rem 0 0.25rem;
}
@ -48,7 +32,7 @@ pre code {
.lntable {
border-spacing: 0;
padding: 0.5rem 0 0.5rem 0;
background-color: var(--code-color);
@include var(background-color, code-color);
border-radius: 0;
border: $code-border;
display: block;
@ -80,7 +64,7 @@ pre code {
.lnt {
display: block;
padding: 0 1rem 0 1rem;
color: $code-color-lineno;
color: $code-lineno-color;
}
.hl {
@ -95,14 +79,14 @@ pre code {
.kr, .k {
font-weight: bold;
color: var(--code-color-keyword);
@include var(color, code-keyword-color);
}
.kt {
font-weight: bold;
color: var(--code-color-type);
@include var(color, code-type-color);
}
.c, .c1 {
color: var(--code-color-comment);
color: $code-comment-color;
}

View File

@ -1,10 +1,6 @@
@import "variables.scss";
@import "mixins.scss";
$margin-width: 30rem;
$margin-inner-offset: 0.5rem;
$margin-outer-offset: 1rem;
@mixin below-two-margins {
@media screen and
(max-width: $container-width-threshold +

21
assets/scss/modes.scss Normal file
View File

@ -0,0 +1,21 @@
:root {
@each $varName, $varDefault in $css-vars {
--#{$varName}: #{$varDefault};
}
}
@media (prefers-color-scheme: dark) {
:root {
--background-color: #{$background-color-dark};
--text-color: white;
--warning-background-color: #{$warning-background-color-dark};
--warning-border-color: #{$warning-border-color-dark};
--target-background-color: #{$target-background-color-dark};
--code-color: #{$code-color-dark};
--code-keyword-color: #{$code-token-color-dark};
--code-type-color: #{$code-token-color-dark};
}
}

View File

@ -2,9 +2,6 @@
@import "mixins.scss";
@import "margin.scss";
$sidenote-padding: 1rem;
$sidenote-highlight-border-width: .2rem;
.sidenote {
&:hover {
.sidenote-label {

View File

@ -1,10 +1,11 @@
@import "variables.scss";
@import "mixins.scss";
@import "toc.scss";
@import "modes.scss";
body {
background-color: var(--background-color);
color: var(--text-color);
@include var(background-color, background-color);
@include var(color, text-color);
font-family: $font-body;
font-size: 1.0rem;
line-height: 1.5;
@ -24,7 +25,7 @@ h1, h2, h3, h4, h5, h6 {
text-align: center;
&:target {
background-color: var(--target-background-color);
@include var(background-color, target-background-color);
border-radius: 1rem;
}
@ -90,7 +91,7 @@ nav {
a {
padding: 0.25rem 0.75rem 0.25rem .75rem;
text-decoration: none;
color: var(--text-color);
@include var(color, text-color);
display: inline-block;
border-bottom: none;
white-space: nowrap;
@ -130,7 +131,7 @@ h6 {
}
a {
color: var(--text-color);
@include var(color, text-color);
text-decoration: none;
border-bottom: .2rem solid $primary-color;
transition: color 0.25s;
@ -272,8 +273,8 @@ figure {
.warning {
@include bordered-block;
padding: 0.5rem;
background-color: var(--warning-background-color);
border-color: var(--warning-border-color);
@include var(background-color, warning-background-color);
@include var(border-color, warning-border-color);
}
.feather {

View File

@ -2,8 +2,6 @@
@import "mixins.scss";
@import "margin.scss";
$toc-border-color: $code-border-color;
.table-of-contents {
@include margin-content;
@include margin-content-left;
@ -45,7 +43,7 @@ $toc-border-color: $code-border-color;
div.wrapper {
@include bordered-block;
padding: 1rem;
background-color: var(--code-color);
@include var(background-color, code-color);
border-color: $toc-border-color;
box-sizing: border-box;
max-width: 100%;

View File

@ -1,15 +1,13 @@
$container-width: 45rem;
$container-min-padding: 1rem;
$container-width-threshold: $container-width + 2 * $container-min-padding;
$standard-border-width: .075rem;
$primary-color: #36e281;
$border-color: #bfbfbf;
$background-color: white;
$background-color-dark: #1b1d1f;
$code-color: #f0f0f0;
$code-color-dark: lighten($background-color-dark, 10%);
$code-border-color: darken($code-color, 10%);
$standard-border-width: .075rem;
$standard-border: $standard-border-width solid $border-color;
$font-heading: "Lora", serif;
$font-body: "Raleway", serif;
@ -23,25 +21,40 @@ $warning-border-color-dark: $warning-background-color;
$target-background-color: lighten(yellow, 30%);
$target-background-color-dark: #55511c;
$standard-border: $standard-border-width solid $border-color;
$code-color: #f0f0f0;
$code-color-dark: lighten($background-color-dark, 10%);
$code-token-color: black;
$code-token-color-dark: darken(white, 40%);
$code-border-color: darken($code-color, 10%);
$code-lineno-color: grey;
$code-comment-color: grey;
$code-border: $standard-border-width solid $code-border-color;
:root {
--background-color: #{$background-color};
--text-color: black;
--code-color: #{$code-color};
--warning-background-color: #{$warning-background-color};
--warning-border-color: #{$warning-border-color};
--target-background-color: #{$target-background-color};
}
$sidenote-padding: 1rem;
$sidenote-highlight-border-width: .2rem;
@media (prefers-color-scheme: dark) {
:root {
--background-color: #{$background-color-dark};
--text-color: white;
--code-color: #{$code-color-dark};
--warning-background-color: #{$warning-background-color-dark};
--warning-border-color: #{$warning-border-color-dark};
--target-background-color: #{$target-background-color-dark};
}
$margin-width: 30rem;
$margin-inner-offset: 0.5rem;
$margin-outer-offset: 1rem;
$toc-border-color: $code-border-color;
// Default values for CSS variables for fallback.
$css-vars: (
background-color: $background-color,
text-color: black,
warning-background-color: $warning-background-color,
warning-border-color: $warning-border-color,
target-background-color: $target-background-color,
code-color: $code-color,
code-keyword-color: $code-token-color,
code-type-color: $code-token-color,
);
@mixin var($property, $varName) {
#{$property}: map-get($css-vars, $varName);
#{$property}: var(--#{$varName});
}