mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-23 21:02:09 +00:00
Greatly simplify CSS, dark theme fixes
- Changed: Make all color codes 3-char. Shave off a few bytes. - Removed: all responsive layout besides the navigation links. Everything else should work well at all window sizes without making allowances for special cases. - Removed: redundant CSS rules - Added: centered images. Left-aligned images in a center-aligned column of text break flow. - Added: dark mode link colors for visited/active. Active link colors give better a11y. - Fix: don't show unnecessary scrollbar for <pre> blocks Also put more comments in the source to explain why each rule is important. All this shrunk the CSS from 1065 bytes to 882 bytes (17% reduction)
This commit is contained in:
parent
e8f31f9f08
commit
347b2c189b
5 changed files with 77 additions and 76 deletions
2
Makefile
2
Makefile
|
@ -20,7 +20,7 @@ clean:
|
||||||
rm -rf $(OUTPUT_DIR) .hintrc-local
|
rm -rf $(OUTPUT_DIR) .hintrc-local
|
||||||
|
|
||||||
lint-css:
|
lint-css:
|
||||||
stylelint $(CSS_DIR)/main.css $(CSS_DIR)/dark.css $(CSS_DIR)/wide.css
|
stylelint $(CSS_DIR)/main.css $(CSS_DIR)/dark.css
|
||||||
csslint $(CSS_DIR)
|
csslint $(CSS_DIR)
|
||||||
|
|
||||||
lint: lint-css hugo .hintrc-local
|
lint: lint-css hugo .hintrc-local
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
html {
|
html {
|
||||||
background: black;
|
background: #000;
|
||||||
color: white;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #00b1ed;
|
color: #0af;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr {
|
a:visited {
|
||||||
border-color: #5c5c5c;
|
color: #d7c;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:active {
|
||||||
|
color: #f33;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre,
|
pre,
|
||||||
code {
|
code,
|
||||||
border: 1px solid #333;
|
hr {
|
||||||
|
border-color: #333;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/* CSS that adds the bare minimum for a simple layout */
|
||||||
|
|
||||||
|
/* This site's CSS only does 9 things:
|
||||||
|
* 1. sans-serif instead of serif for low-res screens.
|
||||||
|
* 2. Consistent font size; <pre> and <code> shouldn't be smaller.
|
||||||
|
* 3. max text width for readability
|
||||||
|
* 4. single-row nav links widescreen, multiline nav on narrow screens
|
||||||
|
* 5. Bigger "home" link that doubles as a site header
|
||||||
|
* 6. Soft border around code in case it looks too similar to regular
|
||||||
|
* text, and to show it continue across more than one line
|
||||||
|
* 7. Horizontally center inline images; left-aligned stick out.
|
||||||
|
* 8. Padding fixes so the above changes don't make elements misalign.
|
||||||
|
* 9. dark.css changes a few colors if the browser wants dark mode.
|
||||||
|
* Everything else is browser defaults:
|
||||||
|
* default fonts, non-dark-mode colors, etc.
|
||||||
|
*/
|
||||||
html {
|
html {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
@ -5,86 +21,85 @@ html {
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0 auto;
|
margin: auto;
|
||||||
max-width: 50rem;
|
max-width: 50rem;
|
||||||
padding: 2rem;
|
padding: 2rem 5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
header nav {
|
/* The posts list doesn't need bullets; simple spacing and repetition
|
||||||
display: block;
|
* of the "date + title" format is enough to convey separation
|
||||||
padding: 0 0 0.25rem;
|
* between elements.
|
||||||
}
|
*/
|
||||||
|
.posts {
|
||||||
header nav ul {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
list-style-type: none;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
header nav ul li {
|
.posts li {
|
||||||
display: block;
|
|
||||||
padding: 0.5rem 0.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.home {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: bold;
|
|
||||||
padding: 0 0.4rem 1rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* index.html styles */
|
|
||||||
main .posts {
|
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
main .posts li {
|
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
nav ul {
|
||||||
font-size: 1.5rem;
|
/* nav links should look more prominent than normal links */
|
||||||
line-height: 2rem;
|
|
||||||
margin: 1.5rem 0 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
margin: 1.5rem 0 1rem;
|
|
||||||
|
/* Use whitespace instead of bullets to separate nav from article.
|
||||||
|
Also avoid top-padding at the top of the page. */
|
||||||
|
list-style-type: none;
|
||||||
|
margin: 0 0 2rem;
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* nav links should be easy to tap with fat fingers */
|
||||||
|
nav ul li:not(.home) {
|
||||||
|
padding: 0.5rem 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make the home link a bit bigger to serve as a site heading */
|
||||||
|
.home {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 0 0.5rem 0.75rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* single-line nav on widescreen, multi-line nav on narrow screens */
|
||||||
|
@media (min-width: 32rem) {
|
||||||
|
header nav ul li {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
h3 {
|
h3 {
|
||||||
font-size: 1.125rem;
|
line-height: 1.25em;
|
||||||
margin: 1.5rem 0 1rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
|
display: block;
|
||||||
height: auto;
|
height: auto;
|
||||||
margin: 0 auto;
|
margin: auto;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
font-size: 16px;
|
padding: 0 0.25rem;
|
||||||
padding: 0.1rem 0.25rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pre,
|
pre,
|
||||||
code {
|
code {
|
||||||
border: 1px solid #e3e3e3;
|
border: 1px solid #bbb;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre code {
|
pre code {
|
||||||
border: none;
|
border: 0; /* don't border each line in a pre block */
|
||||||
|
padding: 0; /* otherwise the first line in a pre block gets indented. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allow horizontal scroll in a pre block, but don't clip it vertically */
|
||||||
pre {
|
pre {
|
||||||
overflow-x: scroll;
|
/* csslint ignore:start */
|
||||||
overflow-y: visible;
|
overflow: auto visible;
|
||||||
padding: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
/* csslint ignore:end */
|
||||||
margin: 2rem 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
@media (min-width: 32rem) {
|
|
||||||
body {
|
|
||||||
padding: 2rem 5%;
|
|
||||||
}
|
|
||||||
|
|
||||||
header nav {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
header nav ul li {
|
|
||||||
display: inline;
|
|
||||||
padding: 0 0.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.home {
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,6 @@
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ $resources := slice -}}
|
{{ $resources := slice -}}
|
||||||
{{ $resources = $resources | append (resources.Get "/css/main.css") -}}
|
{{ $resources = $resources | append (resources.Get "/css/main.css") -}}
|
||||||
{{ $resources = $resources | append (resources.Get "/css/wide.css") -}}
|
|
||||||
{{ $dark := .Site.Params.dark | default "auto" -}}
|
{{ $dark := .Site.Params.dark | default "auto" -}}
|
||||||
{{ if not (eq $dark "off") -}}
|
{{ if not (eq $dark "off") -}}
|
||||||
{{ $resources = $resources | append (resources.Get "css/dark.css" | resources.ExecuteAsTemplate "dark.css" .) -}}
|
{{ $resources = $resources | append (resources.Get "css/dark.css" | resources.ExecuteAsTemplate "dark.css" .) -}}
|
||||||
|
|
Loading…
Reference in a new issue