├── .eleventy.js ├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ └── demo-request.md ├── .gitignore ├── .nvmrc ├── .vscode └── tasks.json ├── README.md ├── color-token-contrast.md ├── color-tokens.js ├── netlify.toml ├── package-lock.json ├── package.json └── src ├── _data ├── eleventyComputed.js ├── order.js └── siteMeta.js ├── _generate └── feed.njk ├── _includes ├── base.njk ├── code.njk ├── dark-mode.js ├── dropdown.js └── postToCodepen.js ├── assets ├── background-picture │ ├── landscape-w275.jpg │ ├── landscape-w275.webp │ ├── landscape-w683.jpg │ ├── landscape-w683.webp │ ├── landscape-w860.jpg │ └── landscape-w860.webp └── video.mp4 ├── favicon.png ├── fonts ├── recursive-v23-latin-600.woff2 └── recursive-v23-latin-regular.woff2 ├── index.njk ├── sass ├── _color-tokens.scss ├── _dark-mode.scss ├── _demo.scss ├── _fonts.scss ├── _layout.scss ├── _prism.scss ├── _reset.scss ├── _theme.scss ├── _typography.scss └── style.scss ├── smolcss.png └── snippets ├── smol-article-anchors.njk ├── smol-aspect-ratio-gallery.njk ├── smol-avatar-list.njk ├── smol-background-picture.njk ├── smol-breakout-grid.njk ├── smol-card-component.njk ├── smol-container.njk ├── smol-css-grid.njk ├── smol-document-styles.njk ├── smol-flexbox-grid.njk ├── smol-focus-styles.njk ├── smol-grid-centering.njk ├── smol-list-markers.njk ├── smol-responsive-padding.njk ├── smol-responsive-sidebar.njk ├── smol-scroll-snap.njk ├── smol-stack-layout.njk ├── smol-transitions.njk ├── smol-unbreakable-boxes.njk ├── smol-visited-styles.njk ├── snippets.json └── snippets.meta /.eleventy.js: -------------------------------------------------------------------------------- 1 | const Terser = require("terser"); 2 | const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); 3 | const pluginRss = require("@11ty/eleventy-plugin-rss"); 4 | const { 5 | reset, 6 | displayStyles, 7 | grid, 8 | flex, 9 | } = require("./src/_includes/postToCodepen"); 10 | 11 | const collectionSchemas = require("@11tyrocks/eleventy-plugin-collection-schemas"); 12 | 13 | const order = require("./src/_data/order"); 14 | 15 | module.exports = function (eleventyConfig) { 16 | eleventyConfig.addWatchTarget("./src/sass/"); 17 | eleventyConfig.addPassthroughCopy("./src/*.png"); 18 | eleventyConfig.addPassthroughCopy("./src/fonts/"); 19 | eleventyConfig.addPassthroughCopy("./src/assets/"); 20 | 21 | eleventyConfig.addPlugin(syntaxHighlight); 22 | eleventyConfig.addPlugin(pluginRss); 23 | eleventyConfig.addPlugin(collectionSchemas); 24 | 25 | eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`); 26 | 27 | eleventyConfig.addCollection("orderedSnippets", function (collection) { 28 | return collection.getFilteredByTag("snippets").sort((a, b) => { 29 | return order.indexOf(a.fileSlug) - order.indexOf(b.fileSlug); 30 | }); 31 | }); 32 | 33 | eleventyConfig.addNunjucksAsyncFilter("jsmin", async (code, callback) => { 34 | try { 35 | const minified = await Terser.minify(code); 36 | return callback(null, minified.code); 37 | } catch (err) { 38 | console.error("Error during terser minify:", err); 39 | return callback(err, code); 40 | } 41 | }); 42 | 43 | eleventyConfig.addShortcode( 44 | "postToCodepen", 45 | (title, slug, tags, css, html, layout) => { 46 | const description = `Generated from: https://SmolCSS.dev/#${slug}`; 47 | const snippetComment = `/***\n 🟣 SmolCSS Snippet Styles\n */`; 48 | const baseCSS = `\n${css}\n\n${displayStyles}`; 49 | let cssCode = `${reset}\n\n${snippetComment}`; 50 | 51 | let penTags = [...tags]; 52 | penTags[tags.length] = "smolcss"; 53 | 54 | if (layout == "unstyled") { 55 | cssCode = `${snippetComment}\n\n${css}`; 56 | } else if (layout == "flex") { 57 | cssCode += `${flex}${baseCSS}`; 58 | } else if (layout == "grid") { 59 | cssCode += `${grid}${baseCSS}`; 60 | } else { 61 | cssCode += baseCSS; 62 | } 63 | 64 | const penAttributes = { 65 | title: `SmolCSS - ${title}`, 66 | description: description, 67 | tags: penTags, 68 | editors: "110", 69 | layout: "left", 70 | html: `${html}`, 71 | html_pre_processor: "none", 72 | css: cssCode, 73 | css_pre_processor: "scss", 74 | css_starter: "neither", 75 | css_prefix: "autoprefixer", 76 | head: "", 77 | }; 78 | const JSONstring = JSON.stringify(penAttributes) 79 | .replace(/"/g, """) 80 | .replace(/'/g, "'"); 81 | 82 | return `
83 | 84 | 87 |
`; 88 | } 89 | ); 90 | 91 | eleventyConfig.addFilter("removeSmol", function (title) { 92 | return title.replace("Smol ", ""); 93 | }); 94 | 95 | eleventyConfig.setBrowserSyncConfig({ 96 | open: true, 97 | }); 98 | 99 | return { 100 | dir: { 101 | input: "src", 102 | output: "public", 103 | }, 104 | }; 105 | }; 106 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: 5t3ph 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/demo-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Demo request 3 | about: 'Propose a new demo ' 4 | title: 'Suggestion: ' 5 | labels: suggestion 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the solution you'd like** 11 | A concise description of the properties or scenario you'd like to see explored as an addition for SmolCSS.dev 12 | 13 | **Additional context** 14 | Add any other context or screenshots about the request here. 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies installed by npm 2 | node_modules 3 | 4 | # build artefacts 5 | public 6 | css 7 | 8 | # secrets and errors 9 | .env 10 | .log 11 | 12 | # macOS related files 13 | .DS_Store 14 | 15 | # drafts 16 | smol-flexbox-variable-grid.njk -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 18 -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "start", 9 | "label": "Launch Site", 10 | "group": "none", 11 | "presentation": { 12 | "reveal": "always", 13 | "panel": "new" 14 | }, 15 | "runOptions": { 16 | "runOn": "folderOpen" 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmolCSS.dev 2 | 3 | > Minimal snippets for modern CSS layouts and components 4 | 5 | _[Watch me make this with Colby Fayock](https://www.youtube.com/watch?v=nIiOwNb7KR4) and learn about creating an Eleventy site!_ 6 | -------------------------------------------------------------------------------- /color-token-contrast.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Color Token Contrast 3 | --- 4 | 5 | > The following are contrast safe combinations as calculated for _normal_ text based on WCAG AA 4.5 6 | 7 | ## color-surface 8 | - `color-on-surface` 9 | - `color-on-red` 10 | - `color-on-yellow` 11 | - `color-on-blue` 12 | - `color-on-green` 13 | - `color-on-purple` 14 | 15 | ## color-on-surface 16 | - `color-surface` 17 | - `color-red` 18 | - `color-yellow` 19 | - `color-blue` 20 | - `color-green` 21 | - `color-purple` 22 | 23 | ## color-red 24 | - `color-on-surface` 25 | - `color-on-red` 26 | - `color-on-blue` 27 | - `color-on-purple` 28 | 29 | ## color-on-red 30 | - `color-surface` 31 | - `color-red` 32 | - `color-yellow` 33 | - `color-green` 34 | 35 | ## color-yellow 36 | - `color-on-surface` 37 | - `color-on-red` 38 | - `color-on-yellow` 39 | - `color-on-blue` 40 | - `color-on-green` 41 | - `color-on-purple` 42 | 43 | ## color-on-yellow 44 | - `color-surface` 45 | - `color-yellow` 46 | 47 | ## color-blue 48 | - `color-on-surface` 49 | - `color-on-blue` 50 | - `color-on-purple` 51 | 52 | ## color-on-blue 53 | - `color-surface` 54 | - `color-red` 55 | - `color-yellow` 56 | - `color-blue` 57 | - `color-green` 58 | 59 | ## color-green 60 | - `color-on-surface` 61 | - `color-on-red` 62 | - `color-on-blue` 63 | - `color-on-green` 64 | - `color-on-purple` 65 | 66 | ## color-on-green 67 | - `color-surface` 68 | - `color-yellow` 69 | - `color-green` 70 | 71 | ## color-purple 72 | - `color-on-surface` 73 | - `color-on-purple` 74 | 75 | ## color-on-purple 76 | - `color-surface` 77 | - `color-red` 78 | - `color-yellow` 79 | - `color-blue` 80 | - `color-green` 81 | - `color-purple` 82 | -------------------------------------------------------------------------------- /color-tokens.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | name: "surface", 4 | color: "#f5f2f7", 5 | onColor: "#29344B", 6 | }, 7 | { 8 | name: "red", 9 | color: "#FCD4D2", 10 | }, 11 | { 12 | name: "yellow", 13 | color: "#F2E6B1", 14 | }, 15 | { 16 | name: "blue", 17 | color: "#CADFF9", 18 | }, 19 | { 20 | name: "green", 21 | color: "#c6e7d6", 22 | }, 23 | { 24 | name: "purple", 25 | color: "#E0D4F6", 26 | }, 27 | ]; 28 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | # Directory (relative to root of your repo) that contains the deploy-ready 3 | # HTML files and assets generated by the build. If a base directory has 4 | # been specified, include it in the publish directory path. 5 | publish = "public" 6 | 7 | [[redirects]] 8 | from = "/feed/" 9 | to = "/feed/feed.xml" 10 | status = 200 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smolcss", 3 | "version": "0.1.0", 4 | "description": "SmolCSS layouts and components", 5 | "main": "index.html", 6 | "scripts": { 7 | "color-tokens": "a11y-color-tokens --outputDirPath='src/sass' --customPropertiesFormat='root' --compatibilityDocsPath='./'", 8 | "watch:sass": "sass --no-source-map --watch src/sass:public/css", 9 | "watch:eleventy": "eleventy --serve", 10 | "build:sass": "sass --no-source-map src/sass:public/css", 11 | "build:eleventy": "eleventy", 12 | "postbuild": "postcss public/css/*.css -u autoprefixer cssnano -r --no-map", 13 | "start": "npm-run-all color-tokens build:sass --parallel watch:*", 14 | "build": "npm-run-all color-tokens build:sass build:eleventy" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/5t3ph/smolcss.git" 19 | }, 20 | "author": "5t3ph", 21 | "license": "ISC", 22 | "bugs": { 23 | "url": "https://github.com/5t3ph/smolcss/issues" 24 | }, 25 | "homepage": "https://smolcss.dev", 26 | "devDependencies": { 27 | "@11ty/eleventy": "^2.0.1", 28 | "@11ty/eleventy-plugin-rss": "^1.2.0", 29 | "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.0", 30 | "@11tyrocks/eleventy-plugin-collection-schemas": "github:5t3ph/eleventy-plugin-collection-schemas", 31 | "a11y-color-tokens": "^0.7.0", 32 | "autoprefixer": "^10.4.16", 33 | "cssnano": "^6.0.1", 34 | "npm-run-all": "^4.1.5", 35 | "postcss": "^8.4.31", 36 | "postcss-cli": "^10.1.0", 37 | "sass": "^1.69.0", 38 | "terser": "^5.21.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/_data/eleventyComputed.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | metaSchema: function (data) { 3 | return this.metaSchema(data); 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /src/_data/order.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | "smol-css-grid", 3 | "smol-flexbox-grid", 4 | "smol-grid-centering", 5 | "smol-container", 6 | "smol-breakout-grid", 7 | "smol-stack-layout", 8 | "smol-responsive-padding", 9 | "smol-responsive-sidebar", 10 | "smol-aspect-ratio-gallery", 11 | "smol-unbreakable-boxes", 12 | "smol-background-picture", 13 | "smol-card-component", 14 | "smol-avatar-list", 15 | "smol-scroll-snap", 16 | "smol-focus-styles", 17 | "smol-visited-styles", 18 | "smol-document-styles", 19 | "smol-transitions", 20 | "smol-article-anchors", 21 | "smol-list-markers", 22 | ]; 23 | -------------------------------------------------------------------------------- /src/_data/siteMeta.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | url: process.env.URL || "http://localhost:8080", 3 | siteName: "SmolCSS", 4 | siteDescription: "Minimal snippets for modern CSS layouts and components", 5 | authorName: "Stephanie Eckles", 6 | }; 7 | -------------------------------------------------------------------------------- /src/_generate/feed.njk: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: feed/feed.xml 3 | eleventyExcludeFromCollections: true 4 | --- 5 | 6 | 7 | {{ siteMeta.siteName }} 8 | {{ siteMeta.siteDescription }} 9 | {% set absoluteUrl %}{{ '/feed/' | url | absoluteUrl(siteMeta.url) }}{% endset %} 10 | 11 | 12 | {{ collections.snippets | rssLastUpdatedDate }} 13 | {{ siteMeta.url }}/ 14 | 15 | {{ siteMeta.authorName }} 16 | 17 | {%- for item in collections.snippets | reverse %} 18 | {% set absolutePostUrl %}{{ '/' | url | absoluteUrl(siteMeta.url) }}#{{item.fileSlug}}{% endset %} 19 | 20 | {{ item.data.title }} 21 | 22 | {{ item.date | rssDate }} 23 | {{ absolutePostUrl }} 24 | {{ item.templateContent | htmlToAbsoluteUrls(absoluteUrl) }} 25 | 26 | {%- endfor %} 27 | -------------------------------------------------------------------------------- /src/_includes/base.njk: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{ title }} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | {% if 'smolcss' in siteMeta.url %} 20 | 21 | 22 | {% endif %} 23 | 29 | 30 | 31 | 32 |
33 |

{{ title }}

34 |

{{ description }}

35 | Created by Stephanie Eckles of ModernCSS.dev 36 | 41 |
42 | 52 |
53 | {{ content | safe }} 54 |
55 | 58 | 65 | 66 | {% set js %} 67 | {% include "dark-mode.js" %} 68 | {% include "dropdown.js" %} 69 | {% endset %} 70 | 73 | 93 | 94 | -------------------------------------------------------------------------------- /src/_includes/code.njk: -------------------------------------------------------------------------------- 1 | {{ codepenForm | safe }} 2 | 3 | 4 | {{ description | safe }} 5 | 6 | {%- if hideDemo !== 'true' -%} 7 | 10 | {%- endif %} 11 | 12 |
13 | CSS for "{{ meta.title }}" 14 | 15 | ```css 16 | {{- css | safe }} 17 | ``` 18 |
19 | 20 | {%- if hideDemo !== 'true' -%} 21 |
22 | {{ html | safe }} 23 |
24 | {%- endif %} 25 | 26 | {%- if resourceLink -%} 27 | 30 | {%- endif %} -------------------------------------------------------------------------------- /src/_includes/dark-mode.js: -------------------------------------------------------------------------------- 1 | // Inspired by: 2 | // @link https://piccalil.li/tutorial/create-a-user-controlled-dark-or-light-mode 3 | // @link https://web.dev/prefers-color-scheme/ 4 | 5 | const COLOR_MODE = "user-color-scheme"; 6 | const darkModeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); 7 | const darkMode = darkModeMediaQuery.matches; 8 | const modeToggle = document.getElementById("mode-toggle"); 9 | const initColorMode = localStorage.getItem(COLOR_MODE); 10 | 11 | const applySetting = (passedSetting) => { 12 | let currentSetting = passedSetting || localStorage.getItem(COLOR_MODE); 13 | 14 | if (currentSetting) { 15 | document.documentElement.setAttribute( 16 | "data-user-color-scheme", 17 | currentSetting 18 | ); 19 | if (currentSetting === "dark") { 20 | modeToggle.checked = true; 21 | } else { 22 | modeToggle.checked = false; 23 | } 24 | } else if (darkMode) { 25 | document.documentElement.setAttribute("data-user-color-scheme", "dark"); 26 | modeToggle.checked = true; 27 | } 28 | }; 29 | 30 | const toggleSetting = () => { 31 | let currentSetting = localStorage.getItem(COLOR_MODE); 32 | 33 | switch (currentSetting) { 34 | case null: 35 | currentSetting = darkMode ? "dark" : "light"; 36 | break; 37 | case "light": 38 | currentSetting = "light"; 39 | break; 40 | case "dark": 41 | currentSetting = "dark"; 42 | break; 43 | } 44 | 45 | return currentSetting; 46 | }; 47 | 48 | modeToggle.addEventListener("change", (event) => { 49 | if (event.target.checked) { 50 | localStorage.setItem(COLOR_MODE, "dark"); 51 | } else { 52 | localStorage.setItem(COLOR_MODE, "light"); 53 | } 54 | 55 | applySetting(toggleSetting()); 56 | }); 57 | 58 | applySetting(); 59 | 60 | darkModeMediaQuery.addEventListener("change", (e) => { 61 | if (initColorMode === null) applySetting(e.matches ? "dark" : "light"); 62 | }); 63 | -------------------------------------------------------------------------------- /src/_includes/dropdown.js: -------------------------------------------------------------------------------- 1 | const toc = document.getElementById("toc"); 2 | const dropdown = toc.querySelector("ul"); 3 | 4 | document.addEventListener("keydown", (e) => { 5 | if (toc.open && e.key === "Escape") { 6 | toc.open = false; 7 | toc.querySelector("summary").focus(); 8 | } 9 | }); 10 | 11 | document.body.addEventListener("mousedown", (e) => { 12 | if (toc.open && e.target.nodeName != "A" && e.target.nodeName != "SUMMARY") { 13 | toc.open = false; 14 | } 15 | }); 16 | 17 | const links = document.querySelectorAll("a"); 18 | 19 | links.forEach((link) => { 20 | link.addEventListener("focus", (e) => { 21 | const { path } = e; 22 | const dropdownLink = path.filter((item) => item.id == "toc"); 23 | 24 | if (toc.open && !dropdownLink.length) { 25 | toc.open = false; 26 | } 27 | }); 28 | }); 29 | 30 | window.addEventListener("hashchange", () => { 31 | if (toc.open) { 32 | toc.open = false; 33 | } 34 | }); 35 | -------------------------------------------------------------------------------- /src/_includes/postToCodepen.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | reset: ` 3 | /* Box sizing rules */ 4 | *, 5 | *::before, 6 | *::after { 7 | box-sizing: border-box; 8 | } 9 | 10 | /* Remove default margin */ 11 | body, 12 | h1, 13 | h2, 14 | h3, 15 | h4, 16 | p { 17 | margin: 0; 18 | } 19 | 20 | /* Set core body defaults */ 21 | body { 22 | min-height: 100vh; 23 | text-rendering: optimizeSpeed; 24 | line-height: 1.65; 25 | padding: 2rem; 26 | background-color: #f5f2f7; 27 | color: #29344B; 28 | font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial, sans-serif; 29 | }`, 30 | displayStyles: ` 31 | /* Additional demo styles from SmolCSS.dev 32 | Not all styles may be needed for this pen */ 33 | body > ul { 34 | list-style: none; 35 | margin: 0; 36 | 37 | &:not([data-padding-unset]) { 38 | padding: 0; 39 | } 40 | } 41 | 42 | [class*="smol"]:not([data-component]) > *:not([data-unstyled]) { 43 | display: grid; 44 | padding: 1rem; 45 | background-color: #E0D4F6; 46 | color: #675883; 47 | font-size: clamp(1.5rem, 4vw, 2rem); 48 | font-weight: bold; 49 | text-align: center; 50 | border-radius: 0.15em; 51 | border: 1px dashed; 52 | 53 | &:not([data-text]) { 54 | place-content: center; 55 | } 56 | 57 | &[data-text] { 58 | font-size: 1.15rem; 59 | text-align: left; 60 | } 61 | } 62 | 63 | [data-container-style] { 64 | outline: 2px dotted #29344B; 65 | }`, 66 | grid: ` 67 | .smol-css-grid { 68 | --min: 20ch; 69 | --gap: 1rem; 70 | 71 | display: grid; 72 | grid-gap: var(--gap); 73 | grid-template-columns: repeat(auto-fit, minmax(var(--min), 1fr)); 74 | }`, 75 | flex: ` 76 | .smol-flexbox-grid { 77 | --min: 15ch; 78 | --gap: 1rem; 79 | 80 | display: flex; 81 | flex-wrap: wrap; 82 | gap: var(--gap); 83 | } 84 | 85 | .smol-flexbox-grid > * { 86 | flex: 1 1 var(--min); 87 | }`, 88 | }; 89 | -------------------------------------------------------------------------------- /src/assets/background-picture/landscape-w275.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/background-picture/landscape-w275.jpg -------------------------------------------------------------------------------- /src/assets/background-picture/landscape-w275.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/background-picture/landscape-w275.webp -------------------------------------------------------------------------------- /src/assets/background-picture/landscape-w683.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/background-picture/landscape-w683.jpg -------------------------------------------------------------------------------- /src/assets/background-picture/landscape-w683.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/background-picture/landscape-w683.webp -------------------------------------------------------------------------------- /src/assets/background-picture/landscape-w860.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/background-picture/landscape-w860.jpg -------------------------------------------------------------------------------- /src/assets/background-picture/landscape-w860.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/background-picture/landscape-w860.webp -------------------------------------------------------------------------------- /src/assets/video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/assets/video.mp4 -------------------------------------------------------------------------------- /src/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/favicon.png -------------------------------------------------------------------------------- /src/fonts/recursive-v23-latin-600.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/fonts/recursive-v23-latin-600.woff2 -------------------------------------------------------------------------------- /src/fonts/recursive-v23-latin-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/fonts/recursive-v23-latin-regular.woff2 -------------------------------------------------------------------------------- /src/index.njk: -------------------------------------------------------------------------------- 1 | --- 2 | title: "SmolCSS" 3 | description: "Minimal snippets for modern CSS layouts and components" 4 | layout: "base.njk" 5 | --- 6 | 7 | {% for snippet in collections.orderedSnippets %} 8 | {# {% if loop.index0 === 1 %} 9 |

Hey there! Registration is open for my July workshop "Level-Up With Modern CSS" — register today!

10 | {% endif %} #} 11 |
12 |
13 |

{{ snippet.data.meta.title }}

14 | 15 | 16 | 17 | 18 |
19 |
20 | 27 | {{ snippet.templateContent | safe }} 28 |
29 | {% endfor %} 30 | -------------------------------------------------------------------------------- /src/sass/_color-tokens.scss: -------------------------------------------------------------------------------- 1 | /* 🛑 STOP! 2 | Do not change this file directly. 3 | Modify colors in color-tokens.js 4 | */ 5 | 6 | $color-surface: #f5f2f7 !default; 7 | $color-on-surface: #29344B !default; 8 | $color-red: #FCD4D2 !default; 9 | $color-on-red: #885452 !default; 10 | $color-yellow: #F2E6B1 !default; 11 | $color-on-yellow: #71673C !default; 12 | $color-blue: #CADFF9 !default; 13 | $color-on-blue: #4B6381 !default; 14 | $color-green: #c6e7d6 !default; 15 | $color-on-green: #4C695A !default; 16 | $color-purple: #E0D4F6 !default; 17 | $color-on-purple: #675883 !default; 18 | 19 | $base-color-tokens: ("surface", "red", "yellow", "blue", "green", "purple"); 20 | 21 | $color-tokens: ( 22 | "color-surface": $color-surface, 23 | "color-on-surface": $color-on-surface, 24 | "color-red": $color-red, 25 | "color-on-red": $color-on-red, 26 | "color-yellow": $color-yellow, 27 | "color-on-yellow": $color-on-yellow, 28 | "color-blue": $color-blue, 29 | "color-on-blue": $color-on-blue, 30 | "color-green": $color-green, 31 | "color-on-green": $color-on-green, 32 | "color-purple": $color-purple, 33 | "color-on-purple": $color-on-purple 34 | ) !default; 35 | 36 | :root { 37 | --color-surface: #{$color-surface}; 38 | --color-on-surface: #{$color-on-surface}; 39 | --color-red: #{$color-red}; 40 | --color-on-red: #{$color-on-red}; 41 | --color-yellow: #{$color-yellow}; 42 | --color-on-yellow: #{$color-on-yellow}; 43 | --color-blue: #{$color-blue}; 44 | --color-on-blue: #{$color-on-blue}; 45 | --color-green: #{$color-green}; 46 | --color-on-green: #{$color-on-green}; 47 | --color-purple: #{$color-purple}; 48 | --color-on-purple: #{$color-on-purple}; 49 | } -------------------------------------------------------------------------------- /src/sass/_dark-mode.scss: -------------------------------------------------------------------------------- 1 | $base-color-tokens: ("surface", "red", "yellow", "blue", "green", "purple"); 2 | 3 | @mixin dark-mode() { 4 | @each $color in $base-color-tokens { 5 | $onColor: if( 6 | $color == "surface", 7 | scale-color(color("color-#{$color}"), $lightness: -10%), 8 | color("color-#{$color}") 9 | ); 10 | 11 | --color-#{$color}: #{color("color-on-#{$color}")}; 12 | --color-on-#{$color}: #{$onColor}; 13 | } 14 | 15 | code[class*="language-"], 16 | pre[class*="language-"] { 17 | --color-on-surface: var(--color-surface); 18 | --color-surface: var(--color-on-surface); 19 | } 20 | 21 | pre[class*="language-"] { 22 | border: 1px solid; 23 | } 24 | } 25 | 26 | @media (prefers-color-scheme: dark) { 27 | :root:not([data-user-color-scheme="light"]) { 28 | @include dark-mode(); 29 | } 30 | } 31 | 32 | :root[data-user-color-scheme="dark"] { 33 | @include dark-mode(); 34 | } 35 | 36 | .mode-toggle { 37 | display: inline-grid; 38 | grid-gap: 0.5em; 39 | align-items: center; 40 | grid-template-areas: "input label"; 41 | grid-template-columns: 2.5rem auto; 42 | justify-self: center; 43 | margin-top: 3rem; 44 | font-size: 0.8rem; 45 | letter-spacing: 0.05em; 46 | font-weight: 600; 47 | 48 | input { 49 | opacity: 0; 50 | } 51 | 52 | &-control, 53 | input { 54 | width: 2rem; 55 | height: 0.8rem; 56 | grid-area: input; 57 | font-size: 1rem; 58 | } 59 | 60 | &-control { 61 | border-radius: 1em; 62 | background-color: var(--color-on-purple); 63 | display: inline-grid; 64 | align-items: center; 65 | opacity: 0.8; 66 | 67 | &::before { 68 | --switch-color: var(--color-surface); 69 | --switch-x: 0%; 70 | 71 | content: ""; 72 | width: 1em; 73 | height: 1em; 74 | border-radius: 50%; 75 | background-color: var(--switch-color); 76 | transform: translateY(-8%) translateX(var(--switch-x)); 77 | transition: all 120ms ease-in-out; 78 | border: 2px solid var(--color-on-purple); 79 | } 80 | } 81 | 82 | input:checked + &-control::before { 83 | --switch-color: var(--color-purple); 84 | --switch-x: 100%; 85 | } 86 | 87 | input:focus + &-control::before { 88 | box-shadow: 0 0 0 3px var(--color-on-surface); 89 | } 90 | input:checked:focus + &-control::before { 91 | box-shadow: 0 0 0 3px var(--color-surface); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/sass/_demo.scss: -------------------------------------------------------------------------------- 1 | .demo { 2 | padding: 1.5rem; 3 | border: 1px solid var(--color-on-purple); 4 | 5 | @media (max-width: 928px) { 6 | max-width: calc(100vi - 2rem); 7 | } 8 | 9 | > ul { 10 | list-style: none; 11 | margin: 0; 12 | 13 | &:not([data-padding-unset]) { 14 | padding: 0; 15 | } 16 | 17 | @media (max-width: 768px) { 18 | &:not([data-component]) { 19 | --min: 6ch; 20 | } 21 | } 22 | } 23 | 24 | [class*="smol"]:not([data-component]) > *:not([data-unstyled]) { 25 | display: grid; 26 | padding: 1rem; 27 | background-color: var(--color-purple); 28 | color: var(--color-on-purple); 29 | font-size: clamp(1.5rem, 4vi, 2rem); 30 | font-weight: bold; 31 | text-align: center; 32 | border-radius: 0.15em; 33 | border: 1px dashed; 34 | 35 | &:not([data-text]) { 36 | place-content: center; 37 | } 38 | 39 | &[data-text] { 40 | font-size: 1.15rem; 41 | text-align: left; 42 | } 43 | } 44 | 45 | [data-container-style] { 46 | outline: 2px dotted var(--color-on-surface); 47 | } 48 | 49 | [data-component][class*="component"] { 50 | --component-surface: #{color("color-surface")}; 51 | --on-component-surface: #{color("color-on-surface")}; 52 | background-color: var(--component-surface); 53 | color: var(--on-component-surface); 54 | } 55 | 56 | &[data-layout="centered"] { 57 | display: grid; 58 | place-content: center; 59 | min-height: 10rem; 60 | } 61 | } 62 | 63 | // Seeking a pointer because @supports for `resize` 64 | // returns false positive on iOS 65 | @media (any-hover: hover) and (any-pointer: fine) { 66 | .demo:not(.no-resize) { 67 | position: relative; 68 | resize: horizontal; 69 | overflow: auto; 70 | 71 | &::after { 72 | content: "Resize me!"; 73 | position: absolute; 74 | right: 0.85rem; 75 | bottom: 0.65rem; 76 | font-size: 0.8rem; 77 | line-height: 0; 78 | color: var(--color-on-purple); 79 | } 80 | } 81 | } 82 | 83 | @media not all and (min-resolution: 0.001dpcm) { 84 | .demo { 85 | resize: none; 86 | 87 | &::after { 88 | content: ""; 89 | } 90 | } 91 | } 92 | 93 | .smol-focus-styles { 94 | display: grid; 95 | gap: 2rem; 96 | 97 | li { 98 | display: grid; 99 | gap: 0.5rem; 100 | justify-content: start; 101 | } 102 | 103 | button { 104 | color: var(--color-on-purple); 105 | background-color: var(--color-purple); 106 | border-style: solid; 107 | border-radius: 4px; 108 | font: inherit; 109 | padding: 0.25em 0.5em; 110 | cursor: pointer; 111 | } 112 | } 113 | 114 | .demo .smol-breakout-grid { 115 | --max-content-width: min(50ch, 50vi); 116 | 117 | @media (width < 80ch) { 118 | --breakout-difference: 0.4; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/sass/_fonts.scss: -------------------------------------------------------------------------------- 1 | /* recursive-regular - latin */ 2 | @font-face { 3 | font-family: "Recursive"; 4 | font-style: normal; 5 | font-weight: 400; 6 | font-display: swap; 7 | src: local(""), 8 | url("../fonts/recursive-v23-latin-regular.woff2") format("woff2"); 9 | } 10 | /* recursive-600 - latin */ 11 | @font-face { 12 | font-family: "Recursive"; 13 | font-style: normal; 14 | font-weight: 600; 15 | font-display: swap; 16 | src: local(""), url("../fonts/recursive-v23-latin-600.woff2") format("woff2"); 17 | } 18 | -------------------------------------------------------------------------------- /src/sass/_layout.scss: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: var(--color-surface); 3 | color: var(--color-on-surface); 4 | } 5 | 6 | [id] { 7 | scroll-margin-top: 4em; 8 | 9 | &:target { 10 | position: relative; 11 | 12 | &::before { 13 | content: "Aww, you came to see me!"; 14 | position: absolute; 15 | top: -1.5rem; 16 | font-size: 0.9rem; 17 | font-style: italic; 18 | color: var(--color-on-blue); 19 | } 20 | } 21 | } 22 | 23 | header, 24 | main, 25 | aside { 26 | padding: 1rem; 27 | } 28 | 29 | header { 30 | color: var(--color-on-purple); 31 | background-color: var(--color-purple); 32 | min-height: 30vb; 33 | display: grid; 34 | place-content: center; 35 | text-align: center; 36 | border-bottom: 2px dashed; 37 | 38 | small { 39 | margin-top: 0.5rem; 40 | } 41 | } 42 | 43 | main { 44 | display: grid; 45 | grid-gap: 5rem; 46 | grid-gap: max(15vb, 5rem); 47 | } 48 | 49 | main, 50 | aside { 51 | max-width: 60rem; 52 | max-width: 100ch; 53 | margin: 8vb auto; 54 | } 55 | 56 | body > footer { 57 | background-color: var(--color-purple); 58 | color: var(--color-on-purple); 59 | text-align: center; 60 | padding: 1rem; 61 | 62 | > :last-child { 63 | margin-top: 0.5rem; 64 | } 65 | } 66 | 67 | aside { 68 | border-top: 1px dashed; 69 | color: var(--color-on-purple); 70 | } 71 | 72 | article { 73 | max-width: 60rem; 74 | max-width: calc(100ch - 2rem); 75 | 76 | > p + p { 77 | margin-top: 1rem; 78 | } 79 | 80 | footer { 81 | margin-top: 1rem; 82 | font-size: 0.9rem; 83 | } 84 | } 85 | 86 | details:not(#toc) { 87 | margin-top: 2rem; 88 | 89 | summary { 90 | background-color: var(--color-on-surface); 91 | color: var(--color-surface); 92 | } 93 | } 94 | 95 | summary { 96 | cursor: pointer; 97 | padding: 0.5em; 98 | 99 | &:focus { 100 | outline: 2px solid transparent; 101 | box-shadow: inset 0 0 0 2px var(--color-purple), 102 | 0 0 0 2px var(--color-on-purple); 103 | border-radius: 0.15em; 104 | } 105 | } 106 | 107 | $category-colors: ( 108 | "layout": "red", 109 | "component": "yellow", 110 | "grid": "blue", 111 | "flexbox": "green", 112 | ); 113 | 114 | @each $category, $color in $category-colors { 115 | .category-#{$category} { 116 | background-color: var(--color-#{$color}); 117 | color: var(--color-on-#{$color}); 118 | } 119 | } 120 | 121 | .actions { 122 | --item-padding: 0.15em 0.35em; 123 | 124 | display: grid; 125 | grid-gap: 1rem; 126 | justify-content: start; 127 | align-items: center; 128 | margin: 0.5rem 0 1.5rem; 129 | font-size: 0.85rem; 130 | 131 | @media (min-width: 30rem) { 132 | grid-auto-flow: column; 133 | } 134 | 135 | button { 136 | display: inline-flex; 137 | align-items: center; 138 | padding: var(--item-padding); 139 | border: 1px solid var(--color-on-blue); 140 | font: inherit; 141 | background-color: var(--color-on-blue); 142 | color: var(--color-blue); 143 | border-radius: 0.25em; 144 | line-height: inherit; 145 | cursor: pointer; 146 | 147 | svg { 148 | fill: currentColor; 149 | width: 1.25em; 150 | margin-right: 0.5em; 151 | } 152 | 153 | &:focus { 154 | outline: 2px solid transparent; 155 | box-shadow: 0 0 0 2px var(--color-blue), 0 0 0 4px var(--color-on-blue); 156 | } 157 | } 158 | } 159 | 160 | .categories { 161 | margin: 0; 162 | padding: 0; 163 | list-style: none; 164 | display: flex; 165 | gap: 1rem; 166 | 167 | li { 168 | padding: var(--item-padding); 169 | border: 1px dotted; 170 | border-radius: 0.25em; 171 | } 172 | } 173 | 174 | .link-github { 175 | display: inline-flex; 176 | align-items: center; 177 | line-height: 1; 178 | justify-self: center; 179 | margin-top: 1.25rem; 180 | margin-bottom: 1.25rem; 181 | 182 | svg { 183 | width: 1.25em; 184 | fill: currentColor; 185 | margin-right: 0.25em; 186 | transform: translateY(-5%); 187 | } 188 | } 189 | 190 | .hidden { 191 | width: 0; 192 | height: 0; 193 | overflow: hidden; 194 | position: absolute; 195 | } 196 | 197 | .headline { 198 | display: grid; 199 | grid-template-columns: min-content auto; 200 | 201 | .anchor { 202 | grid-row-start: 1; 203 | align-self: start; 204 | font-size: 1rem; 205 | line-height: 1; 206 | transform: translateX(-50%) translateY(25%); 207 | text-decoration: none; 208 | opacity: 0.75; 209 | 210 | &:hover, 211 | &:focus { 212 | text-decoration: underline; 213 | text-underline-offset: 0.25em; 214 | opacity: 1; 215 | } 216 | } 217 | } 218 | 219 | nav { 220 | position: sticky; 221 | top: -1px; 222 | z-index: 1; 223 | background-color: var(--color-blue); 224 | border-bottom: 1px solid var(--color-on-blue); 225 | } 226 | 227 | #toc { 228 | position: relative; 229 | margin: 0 auto; 230 | width: fit-content; 231 | 232 | summary { 233 | color: var(--color-on-blue); 234 | } 235 | 236 | ol { 237 | margin: 0; 238 | padding: 0.5rem 1rem 0.5rem 2.5rem; 239 | position: absolute; 240 | left: 50%; 241 | transform: translateX(-50%); 242 | width: min(35ch, 90vi); 243 | max-height: calc(100vb - 4em); 244 | overflow-y: auto; 245 | background: var(--color-surface); 246 | box-shadow: 0.15em 0.15em 0.3em -0.1em rgba(black, 0.45); 247 | border-radius: 0.25em; 248 | border: 1px solid; 249 | z-index: 1; 250 | 251 | a { 252 | display: block; 253 | line-height: 1.3; 254 | text-decoration: none; 255 | padding: 0.5em 0; 256 | } 257 | 258 | li + li a { 259 | border-top: 1px solid var(--color-purple); 260 | } 261 | 262 | li::marker { 263 | color: var(--color-on-purple); 264 | } 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /src/sass/_prism.scss: -------------------------------------------------------------------------------- 1 | code[class*="language-"], 2 | pre[class*="language-"] { 3 | @each $color in $code-colors { 4 | --color-#{$color}: #{scale-color( 5 | color("color-#{$color}"), 6 | $lightness: -18% 7 | )}; 8 | } 9 | 10 | color: var(--color-surface); 11 | background: none; 12 | font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; 13 | text-align: left; 14 | white-space: pre; 15 | word-spacing: normal; 16 | word-break: normal; 17 | word-wrap: normal; 18 | line-height: 1.5; 19 | tab-size: 4; 20 | hyphens: none; 21 | } 22 | 23 | /* Code blocks */ 24 | pre[class*="language-"] { 25 | padding: 1em; 26 | margin: 0; 27 | overflow: auto; 28 | max-width: calc(100vi - 2rem); 29 | } 30 | 31 | :not(pre) > code[class*="language-"], 32 | pre[class*="language-"] { 33 | background: var(--color-on-surface); 34 | } 35 | 36 | /* Inline code */ 37 | :not(pre) > code[class*="language-"] { 38 | padding: 0.1em; 39 | border-radius: 0.3em; 40 | white-space: normal; 41 | } 42 | 43 | .token.comment, 44 | .token.prolog, 45 | .token.doctype, 46 | .token.cdata { 47 | color: #d4d0ab; 48 | } 49 | 50 | .token.punctuation { 51 | color: #f9f9f9; 52 | } 53 | 54 | .token.property, 55 | .token.tag, 56 | .token.constant, 57 | .token.symbol, 58 | .token.deleted { 59 | color: var(--color-blue); 60 | } 61 | 62 | .token.boolean, 63 | .token.number { 64 | color: var(--color-green); 65 | } 66 | 67 | .token.selector, 68 | .token.attr-name, 69 | .token.string, 70 | .token.char, 71 | .token.builtin, 72 | .token.inserted { 73 | color: var(--color-purple); 74 | } 75 | 76 | .token.operator, 77 | .token.entity, 78 | .token.url, 79 | .language-css .token.string, 80 | .language-scss .token.string, 81 | .style .token.string, 82 | .token.variable { 83 | color: var(--color-red); 84 | } 85 | 86 | .token.function { 87 | color: var(--color-green); 88 | } 89 | 90 | .token.atrule, 91 | .token.attr-value { 92 | color: var(--color-purple); 93 | } 94 | 95 | .token.keyword { 96 | color: var(--color-blue); 97 | } 98 | 99 | .token.regex, 100 | .token.important { 101 | color: var(--color-yellow); 102 | } 103 | 104 | .token.important, 105 | .token.bold { 106 | font-weight: bold; 107 | } 108 | 109 | .token.italic { 110 | font-style: italic; 111 | } 112 | 113 | .token.entity { 114 | cursor: help; 115 | } 116 | 117 | @media screen and (-ms-high-contrast: active) { 118 | code[class*="language-"], 119 | pre[class*="language-"] { 120 | color: windowText; 121 | background: window; 122 | } 123 | 124 | :not(pre) > code[class*="language-"], 125 | pre[class*="language-"] { 126 | background: window; 127 | } 128 | 129 | .token.important { 130 | background: highlight; 131 | color: window; 132 | font-weight: normal; 133 | } 134 | 135 | .token.atrule, 136 | .token.attr-value, 137 | .token.function, 138 | .token.keyword, 139 | .token.operator, 140 | .token.selector { 141 | font-weight: bold; 142 | } 143 | 144 | .token.attr-value, 145 | .token.comment, 146 | .token.doctype, 147 | .token.function, 148 | .token.keyword, 149 | .token.operator, 150 | .token.property, 151 | .token.string { 152 | color: highlight; 153 | } 154 | 155 | .token.attr-value, 156 | .token.url { 157 | font-weight: normal; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/sass/_reset.scss: -------------------------------------------------------------------------------- 1 | // https://piccalil.li/blog/a-modern-css-reset 2 | 3 | /* Box sizing rules */ 4 | *, 5 | *::before, 6 | *::after { 7 | box-sizing: border-box; 8 | } 9 | 10 | /* Remove default margin */ 11 | body, 12 | h1, 13 | h2, 14 | h3, 15 | h4, 16 | p { 17 | margin: 0; 18 | } 19 | 20 | /* Set core body defaults */ 21 | body { 22 | min-height: 100vb; 23 | text-rendering: optimizeSpeed; 24 | line-height: 1.65; 25 | } 26 | 27 | /* A elements that don't have a class get default styles */ 28 | a:not([class]) { 29 | text-decoration-skip-ink: auto; 30 | text-underline-offset: 0.08em; 31 | } 32 | 33 | html:focus-within { 34 | scroll-behavior: smooth; 35 | } 36 | 37 | /* Remove all animations, transitions and smooth scroll for people that prefer not to see them */ 38 | @media (prefers-reduced-motion: reduce) { 39 | html:focus-within { 40 | scroll-behavior: auto; 41 | } 42 | 43 | *, 44 | *::before, 45 | *::after { 46 | animation-duration: 0.01ms !important; 47 | animation-iteration-count: 1 !important; 48 | transition-duration: 0.01ms !important; 49 | scroll-behavior: auto !important; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/sass/_theme.scss: -------------------------------------------------------------------------------- 1 | @function color($key) { 2 | @return map-get($color-tokens, $key); 3 | } 4 | 5 | $code-colors: ("red", "yellow", "blue", "green", "purple"); 6 | -------------------------------------------------------------------------------- /src/sass/_typography.scss: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Recursive", sans-serif; 3 | } 4 | 5 | h1 { 6 | font-size: 3rem; 7 | } 8 | 9 | h2 { 10 | line-height: 1.2; 11 | } 12 | 13 | p { 14 | font-size: 1.15rem; 15 | } 16 | 17 | footer p { 18 | font-size: 1rem; 19 | } 20 | 21 | a { 22 | color: inherit; 23 | 24 | &:focus { 25 | outline: 2px solid currentColor; 26 | } 27 | } 28 | 29 | code:not([class]) { 30 | font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; 31 | font-size: 0.9rem; 32 | 33 | color: var(--color-on-purple); 34 | background-color: var(--color-purple); 35 | padding-right: 0.15em; 36 | padding-left: 0.15em; 37 | white-space: nowrap; 38 | 39 | @supports (font-size: 1ch) { 40 | font-size: 1.75ex; 41 | } 42 | } 43 | 44 | blockquote:not(.smol-unbreakable-box) { 45 | display: inline-block; 46 | font-size: 1.05rem; 47 | margin: 1rem 0 0; 48 | padding: 0.5rem 1rem; 49 | border-radius: 0 0.25em 0.25em 0; 50 | background-color: var(--color-blue); 51 | color: var(--color-on-blue); 52 | border-left: 2px dashed; 53 | 54 | > * { 55 | font-size: inherit; 56 | } 57 | 58 | &.promo { 59 | font-size: 1.25rem; 60 | border: 1px solid; 61 | padding: 2rem; 62 | text-align: center; 63 | border-radius: 0.25em; 64 | max-width: 60ch; 65 | margin-left: auto; 66 | margin-right: auto; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/sass/style.scss: -------------------------------------------------------------------------------- 1 | @import "color-tokens"; 2 | @import "theme"; 3 | @import "dark-mode"; 4 | @import "fonts"; 5 | @import "reset"; 6 | @import "typography"; 7 | @import "layout"; 8 | @import "prism"; 9 | @import "demo"; 10 | -------------------------------------------------------------------------------- /src/smolcss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/5t3ph/smolcss/c2fb68460a142c8fe21153ea3cc57c48d7ab5d53/src/smolcss.png -------------------------------------------------------------------------------- /src/snippets/smol-article-anchors.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Article Anchors" 4 | categories: ["grid", "component", "utility"] 5 | date: 2021-02-24 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | 11 | {% set description %} 12 | 13 | Anchor links have had quite an evolution over the years. Have you checked if your implementation is as accessible as it can be? This demo starts with an accessible DOM structure as [researched by Amber Wilson](https://amberwilson.co.uk/blog/are-your-anchor-links-accessible/), and then uses CSS grid to position the anchor link element. 14 | 15 | **Note**: When using grid or flexbox to change the visual order vs the DOM order, always be cautious of breaking expectations in visual focus order. In this case, we know the headline itself will not contain a link and so we are still able to maintain a visually logical focus order. 16 | 17 | This demo also features an old pseudo class that is often forgotten which is `:target`. Go ahead - click the anchor in this demo or across this site. Thanks to `:target` coupled with `::before`, you'll be greeted with a friendly message to help identify the _target_ of the hashed URL. 18 | 19 | Finally, we've also included `scroll-margin-top` which adds margin _only_ to an active page target. In other words, upon clicking an anchor link or visiting the site with a hashed URL, the scroll point will be above the target by the value of `scroll-margin-top` (_not yet available in Safari_). 20 | 21 | **Bonus**: Notice the properties set on `:focus` to adjust the `outline` position with `outline-offset`. And check out `:hover` to see `text-underline-offset` used to adjust the position of the underline. 22 | 23 | {% endset %} 24 | 25 | {% set css %} 26 | .smol-article-anchor { 27 | display: grid; 28 | grid-template-columns: min-content auto; 29 | position: relative; 30 | margin-top: 2em; 31 | /* You could pull this property out and 32 | generalize it under the selector `[id]` as 33 | it won't affect flow layout or regular margins */ 34 | scroll-margin-top: 2em; 35 | } 36 | 37 | .smol-article-anchor:target::before { 38 | content: "Is it me you're looking for?"; 39 | position: absolute; 40 | font-size: .9rem; 41 | top: -1.25rem; 42 | left: 0; 43 | font-style: italic; 44 | color: currentColor; 45 | } 46 | 47 | .smol-article-anchor a { 48 | grid-row-start: 1; 49 | align-self: start; 50 | font-size: 1rem; 51 | line-height: 1; 52 | /* We're using `transform` vs. margins */ 53 | transform: translateX(-50%) translateY(25%); 54 | text-decoration: none; 55 | /* Be sure to check that your own colors still meet 56 | or exceed 4.5:1 contrast when using lowering opacity */ 57 | opacity: 0.75; 58 | } 59 | 60 | .smol-article-anchor a:hover { 61 | text-decoration: underline; 62 | text-underline-offset: 0.25em; 63 | opacity: 1; 64 | } 65 | 66 | .smol-article-anchor a:focus { 67 | outline: 2px solid currentColor; 68 | outline-offset: 0.15em; 69 | } 70 | 71 | /* Visually hidden while remaining accessible to 72 | assistive tech like screen readers */ 73 | .smol-article-anchor-hidden { 74 | width: 0; 75 | height: 0; 76 | overflow: hidden; 77 | position: absolute; 78 | } 79 | {% endset %} 80 | 81 | {% set html %} 82 |
83 |

A Wonderful Article Headline

84 | 85 | 86 | Section titled A Wonderful Article Headline 87 | 88 |
89 | {% endset %} 90 | 91 | {% set resourceLink %} 92 | 93 | [Learn more about the `:target` pseudo class](https://moderncss.dev/guide-to-advanced-css-selectors-part-two/) in part two of my guide to advanced CSS selectors. 94 | 95 | {% endset %} 96 | 97 | {% set codepenForm %} 98 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 99 | {% endset %} 100 | 101 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-aspect-ratio-gallery.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Aspect Ratio Gallery" 4 | categories: ["flexbox", "layout", "component"] 5 | date: 2021-02-14 6 | templateEngineOverride: md, njk 7 | --- 8 | 9 | {% set description %} 10 | 11 | The `aspect-ratio` property [has support in all major modern browsers](https://caniuse.com/mdn-css_properties_aspect-ratio), and by combining it with `object-fit` and flexbox, we can create a smol responsive gallery. Check out the CSS via your browser Inspector to modify the CSS custom properties on `.smol-aspect-ratio-gallery` and see how they affect this layout. 12 | 13 | The demo initially sets a height as a fallback for browsers that do not yet support `aspect-ratio`, and then uses `@supports` to upgrade to use of `aspect-ratio`. 14 | 15 | Note that `aspect-ratio` isn't just for images, but any element! 16 | 17 | > This solution also uses the [Smol Responsive Flexbox Grid](#smol-flexbox-grid). 18 | 19 | {% endset %} 20 | 21 | {% set css %} 22 | .smol-aspect-ratio-gallery { 23 | --min: 15rem; 24 | --aspect-ratio: 4/3; 25 | --gap: 0; 26 | } 27 | 28 | .smol-aspect-ratio-gallery li { 29 | height: max(25vh, 15rem); 30 | } 31 | 32 | @supports (aspect-ratio: 1) { 33 | .smol-aspect-ratio-gallery li { 34 | aspect-ratio: var(--aspect-ratio); 35 | height: auto; 36 | } 37 | } 38 | 39 | .smol-aspect-ratio-gallery img { 40 | display: block; 41 | object-fit: cover; 42 | width: 100%; 43 | height: 100%; 44 | } 45 | {% endset %} 46 | 47 | {% set html %} 48 | 80 | {% endset %} 81 | 82 | {% set resourceLink %} 83 | 84 | For an alternate method to `aspect-ratio` on this solution, check out my [flexbox gallery egghead lesson](https://egghead.io/lessons/flexbox-create-an-automatically-responsive-flexbox-gallery?af=2s65ms). You may also enjoy my [egghead lesson on `object-fit`](https://egghead.io/lessons/css-apply-aspect-ratio-sizing-to-images-with-css-object-fit?af=2s65ms). 85 | 86 | {% endset %} 87 | 88 | {% set codepenForm %} 89 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html, 'flex' %} 90 | {% endset %} 91 | 92 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-avatar-list.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Avatar List Component" 4 | categories: ["grid", "layout", "component"] 5 | date: 2021-02-20 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | {% set layout %}centered{% endset %} 11 | 12 | {% set description %} 13 | 14 | This smol component, which you may also know as a [facepile](https://indieweb.org/facepile), is possible due to the ability of CSS grid to easily create overlapping content. Paired with CSS custom properties and `calc()` we can make this a contextually resizable component. 15 | 16 | Based on devices capabilities, the grid columns are adjusted to slightly narrower than the `--avatar-size`. Since nothing inherent to CSS grid stops the content overflowing, it forces an overlap based on DOM order of the list items. To ensure perfect circle images, we first use the `--avatar-size` value to explicitly set the list item dimensions. Then by setting both width and height to `100%` on the `img` in addition to `object-fit: cover` and `border-radius: 50%`, we can be assured that regardless of actual image dimensions the contents will be forced into a circle appearance. 17 | 18 | **Bonus trick #1** is the use of layered `box-shadow` values that only set a _spread_ to create the appearance of borders without adding to the computed dimensions of the image. The spread values are set with `em` so that they are relative to the avatar size. And that works because we set the list's `font-size` to `--avatar-size`. 19 | 20 | **Bonus trick #2** is using the _general sibling combinator_ (`~`) so that on hover or `:focus-within` of an `li`, all linked images that follow animate over to reveal more of the hovered avatar. If the number of avatars will cause wrapping, you may want to choose a different effect such as changing the layering via `z-index`. 21 | 22 | 🔎 Pop open your browser devtools and experiment with changing the `--avatar-size` value! 23 | 24 | {% endset %} 25 | 26 | {% set css %} 27 | .smol-avatar-list { 28 | --avatar-size: 3rem; 29 | --avatar-count: 3; 30 | 31 | display: grid; 32 | /* Default to displaying most of the avatar to 33 | enable easier access on touch devices, ensuring 34 | the WCAG touch target size is met or exceeded */ 35 | grid-template-columns: repeat( 36 | var(--avatar-count), 37 | max(44px, calc(var(--avatar-size) / 1.15)) 38 | ); 39 | /* `padding` matches added visual dimensions of 40 | the `box-shadow` to help create a more accurate 41 | computed component size */ 42 | padding: 0.08em; 43 | font-size: var(--avatar-size); 44 | } 45 | 46 | @media (any-hover: hover) and (any-pointer: fine) { 47 | .smol-avatar-list { 48 | /* We create 1 extra cell to enable the computed 49 | width to match the final visual width */ 50 | grid-template-columns: repeat( 51 | calc(var(--avatar-count) + 1), 52 | calc(var(--avatar-size) / 1.75) 53 | ); 54 | } 55 | } 56 | 57 | .smol-avatar-list li { 58 | width: var(--avatar-size); 59 | height: var(--avatar-size); 60 | } 61 | 62 | .smol-avatar-list li:hover ~ li a, 63 | .smol-avatar-list li:focus-within ~ li a { 64 | transform: translateX(33%); 65 | } 66 | 67 | .smol-avatar-list img, 68 | .smol-avatar-list a { 69 | display: block; 70 | border-radius: 50%; 71 | } 72 | 73 | .smol-avatar-list a { 74 | transition: transform 180ms ease-in-out; 75 | } 76 | 77 | .smol-avatar-list img { 78 | width: 100%; 79 | height: 100%; 80 | object-fit: cover; 81 | background-color: #fff; 82 | box-shadow: 0 0 0 0.05em #fff, 0 0 0 0.08em rgba(0, 0, 0, 0.15); 83 | } 84 | 85 | .smol-avatar-list a:focus { 86 | outline: 2px solid transparent; 87 | /* Double-layer trick to work for dark and light backgrounds */ 88 | box-shadow: 0 0 0 0.08em #29344B, 0 0 0 0.12em white; 89 | } 90 | {% endset %} 91 | 92 | {% set html %} 93 | 98 | {% endset %} 99 | 100 | {% set resourceLink %} 101 | 102 | ICYMI earlier - check out my quick [video lesson on object-fit](https://egghead.io/lessons/css-apply-aspect-ratio-sizing-to-images-with-css-object-fit?af=2s65ms) to learn more about how it works. Or you might enjoy more [methods for creating CSS borders](https://moderncss.dev/the-3-css-methods-for-adding-element-borders/) or see an additional [example of using `:focus-within`](https://moderncss.dev/css-only-accessible-dropdown-navigation-menu/). _Source images from [avataaars](https://getavataaars.com/)_. 103 | 104 | {% endset %} 105 | 106 | {% set codepenForm %} 107 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 108 | {% endset %} 109 | 110 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-background-picture.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Background Picture" 4 | categories: ["grid", "component"] 5 | date: 2022-01-05 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | We can reuse the Smol Stack to enable layering the `` element with content as a replacement for using `background-image`. This will let you get the performance benefits of modern image formats like WebP, as well as being able to define `alt` text for accessibility. 12 | 13 | If you haven't worked with the `picture` element before, note that you apply image-related CSS to the internal `img` element. 14 | 15 | To emulate `background-image` type of behavior, we use `object-fit: cover` just like we also used for the [image gallery](#smol-aspect-ratio-gallery). 16 | 17 | **Bonus technique**: improve text contrast of the overlaid content by applying `filter` to the `img`. With the filter, we reduce `brightness` to darken the image while also increasing the `saturate` value to recuperate some of the image vibrancy. These are set with custom properties so that you can easily modify them per-instance if needed to ensure the best contrast. 18 | 19 | > This solution also uses the [Smol Stack Layout](#smol-stack-layout). 20 | 21 | {% endset %} 22 | 23 | {% set css %} 24 | .smol-background-picture img { 25 | --background-img-brightness: 0.45; 26 | --background-img-saturate: 1.25; 27 | 28 | object-fit: cover; 29 | width: 100%; 30 | height: 100%; 31 | /* decrease brightness to improve text contrast */ 32 | filter: 33 | brightness(var(--background-img-brightness)) 34 | saturate(var(--background-img-saturate)); 35 | } 36 | 37 | /* Necessary if not already within a reset */ 38 | .smol-background-picture :is(img, picture) { 39 | display: block; 40 | } 41 | 42 | .smol-background-picture__content { 43 | /* ensure stacking context above the picture */ 44 | position: relative; 45 | align-self: center; 46 | color: #fff; 47 | text-align: center; 48 | padding: 1rem; 49 | } 50 | 51 | .smol-background-picture__content p { 52 | font-size: clamp(1.35rem, 5vw, 1.75rem); 53 | line-height: 1.3; 54 | } 55 | {% endset %} 56 | 57 | {% set html %} 58 |
59 | 60 | 67 | 74 | 75 |
76 |

Text overlaid on a picture element

77 |

Photo by Mark Harpur on Unsplash 78 |

79 |
80 |
81 | {% endset %} 82 | 83 | {% set resourceLink %} 84 | 85 | Learn more about using `picture` in my overview of [handling responsive image display](https://12daysofweb.dev/2021/image-display-elements/). 86 | 87 | {% endset %} 88 | 89 | {% set codepenForm %} 90 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 91 | {% endset %} 92 | 93 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-breakout-grid.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Breakout Grid" 4 | categories: ["grid", "layout"] 5 | date: 2023-10-06 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | Setup a flexible grid layout with collapsing outer columns for easy placement of "breakout" elements. 12 | 13 | The first feature is the use of the `[x-start]`/`[x-end]` syntax to create named grid areas that span more than one column (also works for rows!). In this example, we create three columns where the `grid` area spans all three, and the `content` area is the center column. 14 | 15 | Next, we've set the outer column widths to `1fr` and those columns will collapse first to give the `minmax()` definition for the center column priority, meaning they will eventually compute to a width of `0`. Important to note is that we're only setting _row_ gap, otherwise any column gap would keep space propped open between the middle and outer columns. The `minmax()` definition is explained in the demo for the [Smol Responsive Grid](#smol-css-grid). 16 | 17 | Finally, we assign everything that doesn't have the special `.breakout` class to the `content` named area, and the `.breakout` to the `grid` named area. Be sure to resize the demo to see the outer columns collapse to contain the breakout! 18 | 19 | {% endset %} 20 | 21 | {% set css %} 22 | .smol-breakout-grid { 23 | --max-content-width: 50ch; 24 | --breakout-difference: 0.2; 25 | 26 | /* Compute total allowed grid width to `--breakout-difference` 27 | larger than content area */ 28 | --breakout-grid-width: calc( 29 | var(--max-content-width) + 30 | (var(--max-content-width) * var(--breakout-difference)) 31 | ); 32 | 33 | display: grid; 34 | grid-template-columns: 35 | [grid-start] 1fr 36 | [content-start] minmax( 37 | min(100%, var(--max-content-width)), 38 | 1fr 39 | ) 40 | [content-end] 1fr 41 | [grid-end]; 42 | width: min(100% - 2rem, var(--breakout-grid-width)); 43 | row-gap: 1rem; 44 | margin: 5vb auto; 45 | } 46 | 47 | .smol-breakout-grid > *:not(.breakout) { 48 | grid-column: content; 49 | } 50 | 51 | .smol-breakout-grid > .breakout { 52 | grid-column: grid; 53 | } 54 | {% endset %} 55 | 56 | {% set html %} 57 |
58 |

"Breakout" elements using CSS Grid

59 |

Gummi bears gummies cheesecake donut liquorice sweet roll lollipop chocolate cake macaroon. Dragée powder biscuit.

60 |

I'm a breakout element, when my parent's parent is wide enough to let me expand into the outer columns.

61 |

Jelly sweet tiramisu fruitcake dessert muffin chocolate cake dragée. Donut dragée carrot cake.

62 |
63 | {% endset %} 64 | 65 | {% set resourceLink %} 66 | 67 | 68 | 69 | {% endset %} 70 | 71 | {% set codepenForm %} 72 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 73 | {% endset %} 74 | 75 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-card-component.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Composable Card Component" 4 | categories: ["grid", "flexbox", "component"] 5 | date: 2021-02-14 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | This component features `aspect-ratio` and leans heavily on the pseudo selectors of `:not()`, `:first-child`, and `:last-child`. The result is a composable card component that _just works_ with your desired semantic internal content. 12 | 13 | With [CSS Selectors Level 4](https://drafts.csswg.org/selectors-4/#negation), the enhanced version of `:not()` now allows a selector list. This ability is fairly [well supported in modern browsers](https://caniuse.com/css-not-sel-list). 14 | 15 | A tiny modern CSS progressive enhancement is the use of `text-wrap: pretty` which prevents typography "orphans" by evaluating the last four lines in a text block and makes adjustments so the last line has two or more words. 16 | 17 | **Note**: You may need to create fallbacks for `aspect-ratio` for your unique audience and consider this solution as a progressive enhancement. Review the [Smol Aspect Ratio Gallery](#smol-aspect-ratio-gallery) for one method of creating a fallback. 18 | 19 | > This solution also uses the [Smol Responsive CSS Grid](#smol-css-grid) to contain the cards. 20 | 21 | {% endset %} 22 | 23 | {% set css %} 24 | .smol-card-component { 25 | --img-ratio: 3/2; 26 | 27 | display: flex; 28 | flex-direction: column; 29 | /* Supported for flexbox in modern browsers since April 2021 */ 30 | gap: 1rem; 31 | box-shadow: 0 0 0.5rem hsl(0 0% 0% / 35%); 32 | border-radius: 0.5rem; 33 | } 34 | 35 | .smol-card-component > img { 36 | aspect-ratio: var(--img-ratio); 37 | object-fit: cover; 38 | width: 100%; 39 | } 40 | 41 | .smol-card-component > img:first-child { 42 | border-radius: 0.5rem 0.5rem 0 0; 43 | } 44 | 45 | .smol-card-component > img:last-child { 46 | border-radius: 0 0 0.5rem 0.5rem; 47 | margin-top: auto; 48 | } 49 | 50 | .smol-card-component > :not(img) { 51 | margin-left: 1rem; 52 | margin-right: 1rem; 53 | 54 | /* Prevent typography "orphans" */ 55 | text-wrap: pretty; 56 | } 57 | 58 | .smol-card-component > :not(img):first-child { 59 | margin-top: 1rem; 60 | } 61 | 62 | /* Enhanced `:not()` accepts a selector list, 63 | but as a fallback you can chain `:not()` instead */ 64 | .smol-card-component > :last-of-type:not(img, h2, h3, h4) { 65 | margin-bottom: 1rem; 66 | } 67 | 68 | .smol-card-component > :not(h2, h3, h4) { 69 | font-size: 0.9rem; 70 | } 71 | 72 | .smol-card-component > a { 73 | align-self: start; 74 | } 75 | {% endset %} 76 | 77 | {% set html %} 78 | 98 | {% endset %} 99 | 100 | {% set resourceLink %} 101 | 102 | Learn more about CSS selectors in my two part guide, where part one covers [selectors and combinators](https://moderncss.dev/guide-to-advanced-css-selectors-part-one/) and part two covers [pseudo classes and pseudo elements](https://moderncss.dev/guide-to-advanced-css-selectors-part-two/). 103 | 104 | {% endset %} 105 | 106 | {% set codepenForm %} 107 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html, 'grid' %} 108 | {% endset %} 109 | 110 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-container.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Intrinsic Container" 4 | categories: ["utility", "layout"] 5 | date: 2022-05-05 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | This modern CSS container recipe has three delicious ingredients: the `min()` function, the logical property `margin-inline`, and a custom property - `--container-max` - to make it flexible across infinite contexts. 12 | 13 | Logical properties are writing mode-aware properties that can also serve as shorthand in some cases. Here, `margin-inline` is a shorthand for setting both `margin-left` and `margin-right`, and [`margin-inline` has fairly good support](https://caniuse.com/mdn-css_properties_margin-inline). A PostCSS plugin is available if you're unable to upgrade quite yet for your audience. 14 | 15 | Review the "[Smol Flexible Unbreakable Boxes](#smol-unbreakable-boxes)" for an explanation of `min()`, 16 | 17 | {% endset %} 18 | 19 | {% set css %} 20 | .smol-container { 21 | width: min(100% - 3rem, var(--container-max, 60ch)); 22 | margin-inline: auto; 23 | } 24 | {% endset %} 25 | 26 | {% set html %} 27 |
28 |

Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex quos doloribus autem praesentium quod voluptatem quaerat accusamus labore ullam, omnis corrupti aperiam natus fuga repudiandae repellendus, ipsa enim vitae ut!

29 |
30 | {% endset %} 31 | 32 | {% set resourceLink %} 33 | 34 | Get a bit more info about this container class and [review additional uses of `min()`](https://moderncss.dev/practical-uses-of-css-math-functions-calc-clamp-min-max/#the-modern-css-container-class) and other CSS math functions on ModernCSS.dev. 35 | 36 | {% endset %} 37 | 38 | {% set codepenForm %} 39 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 40 | {% endset %} 41 | 42 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-css-grid.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Responsive CSS Grid" 4 | categories: ["grid", "layout"] 5 | date: 2021-02-10 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | Create an intrinsically responsive grid layout, optionally using a CSS custom property to extend to variable contexts. Each column will resize at the same rate, and items will begin to break to a new row if the width reaches the `--min` value. 12 | 13 | {% endset %} 14 | 15 | {% set css %} 16 | .smol-css-grid { 17 | --min: 15ch; 18 | --gap: 1rem; 19 | 20 | display: grid; 21 | grid-gap: var(--gap); 22 | /* min() with 100% prevents overflow 23 | in extra narrow spaces */ 24 | grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min)), 1fr)); 25 | } 26 | {% endset %} 27 | 28 | {% set html %} 29 | 34 | {% endset %} 35 | 36 | {% set resourceLink %} 37 | 38 | Learn more about [creating a responsive CSS grid solution](https://moderncss.dev/solutions-to-replace-the-12-column-grid/) on ModernCSS.dev 39 | 40 | {% endset %} 41 | 42 | {% set codepenForm %} 43 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 44 | {% endset %} 45 | 46 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-document-styles.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Document Styles" 4 | categories: ["layout"] 5 | date: 2021-02-28 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set hideDemo %}true{% endset %} 10 | 11 | {% set description %} 12 | 13 | In 55 smol lines of CSS, we've created a set of reasonable document styles that is _just enough_ to produce a responsive, easily readable document given the use of semantic HTML. Thanks to `flexbox`, `viewport units`, and `clamp`, it's flexible for variable document lengths. The newly supported `:is()` deserves the most credit in terms of reducing lines of code. 14 | 15 | While lines of code (short or long) certainly doesn't automatically mean "quality", this demo shows that for a simple project you may not need a framework when a little dash of carefully applied CSS will do! 16 | 17 | In fact - it's a great starting point to expand from to use the other smol techniques 😉 18 | 19 | > This particular snippet is for an _entire webpage_ so consequently the demo is not available for direct preview. **Select "Open in Codepen"** to check out the following styles in context! 20 | 21 | {% endset %} 22 | 23 | {% set css %} 24 | * { 25 | box-sizing: border-box; 26 | margin: 0; 27 | } 28 | 29 | body { 30 | display: flex; 31 | flex-direction: column; 32 | min-height: 100vh; 33 | padding: 5vh clamp(1rem, 5vw, 3rem) 1rem; 34 | font-family: system-ui, sans-serif; 35 | line-height: 1.5; 36 | color: #222; 37 | } 38 | 39 | body > * { 40 | --layout-spacing: max(8vh, 3rem); 41 | --max-width: 70ch; 42 | width: min(100%, var(--max-width)); 43 | margin-left: auto; 44 | margin-right: auto; 45 | } 46 | 47 | main { 48 | margin-top: var(--layout-spacing); 49 | } 50 | 51 | footer { 52 | margin-top: auto; 53 | padding-top: var(--layout-spacing); 54 | } 55 | 56 | footer p { 57 | border-top: 1px solid #ccc; 58 | padding-top: 0.25em; 59 | font-size: 0.9rem; 60 | color: #767676; 61 | } 62 | 63 | :is(h1, h2, h3) { 64 | line-height: 1.2; 65 | } 66 | 67 | :is(h2, h3):not(:first-child) { 68 | margin-top: 2em; 69 | } 70 | 71 | article * + * { 72 | margin-top: 1em; 73 | } 74 | 75 | a { 76 | color: navy; 77 | text-underline-offset: 0.15em; 78 | } 79 | {% endset %} 80 | 81 | {% set html %} 82 |
83 |

Minimal Modern CSS Document Styles

84 |
85 |
86 |
87 |

55 lines of CSS

88 |

This set of reasonable document styles is just enough to produce a responsive, easily readable document given the use of semantic HTML. Thanks to flexbox, viewport units, and clamp, it's flexible for variable document lengths. The newlys supported :is() deserves the most credit in terms of reducing lines of code.

89 |

While lines of code (short or long) certainly doesn't automatically mean "quality", this demo shows that for a simple project you may not need a framework when a little dash of carefully applied CSS will do!

90 |

No classes, all selectors and combinators

91 |

Little rusty on your selectors and combinators? Check out my two-part guide to advanced CSS selectors, starting with part one.

92 |

Sugar plum pie sweet roll chocolate bar chocolate cake jujubes jelly beans lollipop. Caramels muffin toffee bonbon icing wafer toffee tiramisu lemon drops.

93 |

Macaroon cheesecake cupcake cotton candy jujubes cupcake. Chocolate sweet sugar plum candy dessert sesame snaps pie. Cupcake pudding oat cake. Halvah candy canes gingerbread tiramisu chupa chups lollipop. Toffee toffee cake. Jelly beans jelly beans chupa chups liquorice dessert donut caramels.

94 |
95 |
96 | 99 | {% endset %} 100 | 101 | {% set resourceLink %} 102 | 103 | **Little rusty on your selectors and combinators**? Check out my two-part guide to advanced CSS selectors, [starting with part one](https://moderncss.dev/guide-to-advanced-css-selectors-part-one/). These styles are used and very slightly expanded (~120 lines) in my [Smol 11ty Starter](https://smol-11ty-starter.netlify.app/). 104 | 105 | {% endset %} 106 | 107 | {% set codepenForm %} 108 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html, 'unstyled' %} 109 | {% endset %} 110 | 111 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-flexbox-grid.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Responsive Flexbox Grid" 4 | categories: ["flexbox", "layout"] 5 | date: 2021-02-10 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | Create an intrinsically responsive grid layout, optionally using a CSS custom property to extend to variable contexts. Each column will resize at the same rate _until_ reaching the `--min` width. At that point, the last item will break to a new row and fill any available space. 12 | 13 | {% endset %} 14 | 15 | {% set css %} 16 | .smol-flexbox-grid { 17 | --min: 10ch; 18 | --gap: 1rem; 19 | 20 | display: flex; 21 | flex-wrap: wrap; 22 | gap: var(--gap); 23 | } 24 | 25 | .smol-flexbox-grid > * { 26 | flex: 1 1 var(--min); 27 | } 28 | {% endset %} 29 | 30 | {% set html %} 31 | 36 | {% endset %} 37 | 38 | {% set resourceLink %} 39 | 40 | Learn more about [creating a responsive flexbox grid solution](https://moderncss.dev/solutions-to-replace-the-12-column-grid/) on ModernCSS.dev 41 | 42 | {% endset %} 43 | 44 | {% set codepenForm %} 45 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 46 | {% endset %} 47 | 48 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-focus-styles.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Focus Styles" 4 | categories: ["utility"] 5 | date: 2021-06-10 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | 11 | {% set description %} 12 | 13 | Focus styles are incredibly important for the accessibility of your application. But, it can be difficult to manage them across changing contexts. 14 | 15 | The following solution takes advantage of custom properties and `:is()` to set reasonable defaults for interactive elements. Then, individual instances can override each setting by simply providing an alternate value for the custom property. 16 | 17 | This solution sets `currentColor` as the `outline-color` which works in many contexts. One that it might not is for buttons, in which case you could update `--outline-color` to use the same color as the button background, for example. 18 | 19 | Additionally, this demonstrates one of the newly available CSS pseudo-class selectors: `focus-visible`. This selector is intended to only display focus styles when the browser detects that they should be visible (you may encounter the term "heuristics"). For now, we've setup some fallbacks so that a focus style is presented even when a browser doesn't support `:focus-visible` quite yet. 20 | 21 | **Note**: Due to using `:focus-visible`, you may not see focus styles on the links and buttons unless you tab to them. 22 | 23 | > Make sure your focus styles have appropriate contrast! If you're working on buttons, [generate an accessible color palette with ButtonBuddy](https://buttonbuddy.dev) 24 | 25 | {% endset %} 26 | 27 | {% set css %} 28 | 29 | /* For "real-world" usage, you do not need to scope 30 | these custom properties */ 31 | .smol-focus-styles :is(a, button, input, textarea, summary) { 32 | /* Using max() ensures at least a value of 2px, 33 | while allowing the possibility of scaling 34 | relative to the component */ 35 | --outline-size: max(2px, 0.08em); 36 | --outline-style: solid; 37 | --outline-color: currentColor; 38 | } 39 | 40 | /* Base :focus styles for fallback purposes */ 41 | .smol-focus-styles :is(a, button, input, textarea, summary):focus { 42 | outline: var(--outline-size) var(--outline-style) var(--outline-color); 43 | outline-offset: var(--outline-offset, var(--outline-size)); 44 | } 45 | 46 | /* Final :focus-visible styles */ 47 | .smol-focus-styles :is(a, button, input, textarea):focus-visible { 48 | outline: var(--outline-size) var(--outline-style) var(--outline-color); 49 | outline-offset: var(--outline-offset, var(--outline-size)); 50 | } 51 | 52 | /* Remove base :focus styles when :focus-visible is available */ 53 | .smol-focus-styles :is(a, button, input, textarea):focus:not(:focus-visible) { 54 | outline: none; 55 | } 56 | 57 | /* Demonstration of customizing */ 58 | .smol-focus-styles li:nth-of-type(2) a { 59 | --outline-style: dashed; 60 | } 61 | 62 | .smol-focus-styles input { 63 | --outline-color: red; 64 | } 65 | 66 | .smol-focus-styles textarea { 67 | --outline-size: 0.25em; 68 | --outline-style: dotted; 69 | --outline-color: green; 70 | } 71 | 72 | .smol-focus-styles li:nth-of-type(4) button { 73 | font-size: 2.5rem; 74 | } 75 | {% endset %} 76 | 77 | {% set html %} 78 | 92 | {% endset %} 93 | 94 | {% set resourceLink %} 95 | 96 | Learn more about `:focus-visible` in my Smashing [article on newly supported CSS pseudo-class selectors](https://www.smashingmagazine.com/2021/04/guide-supported-modern-css-pseudo-class-selectors/). You can also find more [tips on how CSS impacts accessibility](https://moderncss.dev/modern-css-upgrades-to-improve-accessibility/) on ModernCSS. 97 | 98 | {% endset %} 99 | 100 | {% set codepenForm %} 101 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 102 | {% endset %} 103 | 104 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-grid-centering.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Modern Centering" 4 | categories: ["grid", "layout"] 5 | date: 2021-02-10 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | **Put down the CSS centering jokes**! This modern update is often the solution you're looking for to solve your centering woes. 12 | 13 | {% endset %} 14 | 15 | {% set css %} 16 | .smol-centering { 17 | display: grid; 18 | place-content: center; 19 | } 20 | {% endset %} 21 | 22 | {% set html %} 23 |
24 | Feeling Centered 25 |
26 | {% endset %} 27 | 28 | {% set resourceLink %} 29 | 30 | Just in case you're not convinced, [see more centering solutions](https://moderncss.dev/complete-guide-to-centering-in-css/) on ModernCSS.dev 31 | 32 | {% endset %} 33 | 34 | {% set codepenForm %} 35 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 36 | {% endset %} 37 | 38 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-list-markers.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol List Markers" 4 | categories: ["utility"] 5 | date: 2021-02-27 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | 11 | {% set description %} 12 | 13 | Support for `::marker` is now available across all modern browsers! This pseudo-selector allows customizing the "bullet" for unordered lists and the numeral for ordered lists without other pseudo element hacks. 14 | 15 | **Note**: `::marker` only allows a select few properties to be modified including `animation-*`, `color`, `content`, `direction`, `font-*`, `transition-*`, `unicode-bidi`, and `white-space`. 16 | 17 | The use of `::marker` is a great progressive enhancement that can be used safely without any special consideration since the default experience should always acceptable. 18 | 19 | **Bonus**: Check out how the emoji are being inserted thanks to the `content` property's ability to access custom data attributes! (This appears not yet supported for `::marker` in Safari) 20 | 21 | {% endset %} 22 | 23 | {% set css %} 24 | .smol-list-markers { 25 | --marker-color: #A150FB; 26 | 27 | padding: 0; 28 | margin: 0 0 0 2em; 29 | } 30 | 31 | .smol-list-markers li { 32 | padding-left: 0.5em; 33 | } 34 | 35 | .smol-list-markers li + li { 36 | margin-top: 0.5em; 37 | } 38 | 39 | .smol-list-markers li::marker { 40 | color: var(--marker-color); 41 | } 42 | 43 | ul.smol-list-markers li::marker { 44 | content: attr(data-icon); 45 | font-size: 1.15em; 46 | } 47 | 48 | ol.smol-list-markers li::marker { 49 | /* The `list-item` counter is provided by 50 | the browser for lists */ 51 | content: counter(list-item); 52 | font-family: cursive; 53 | font-size: 1.5em; 54 | } 55 | {% endset %} 56 | 57 | {% set html %} 58 |
59 | 64 |
    65 |
  1. Chocolate cake pastry toffee tootsie roll
  2. 66 |
  3. Cake bear claw liquorice oat cake oat cake cheesecake
  4. 67 |
  5. Ice cream soufflé carrot cake jelly-o bonbon
  6. 68 |
69 |
70 | {% endset %} 71 | 72 | {% set resourceLink %} 73 | 74 | If you need more style control, you may still want to use an alternate method. Review my tutorial on creating [totally custom list styles](https://moderncss.dev/totally-custom-list-styles/). 75 | 76 | {% endset %} 77 | 78 | {% set codepenForm %} 79 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html, 'grid' %} 80 | {% endset %} 81 | 82 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-responsive-padding.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Responsive Padding" 4 | categories: ["layout"] 5 | date: 2021-02-11 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | This smol demo is using `clamp()` for responsive padding. The order of `clamp()` values can be interpreted as: the minimum allowed value is `1rem`, the ideal value is `5%` (which will be relative to the element), and the max allowed value is `3rem`. 12 | 13 | In other words, as the element is placed in different contexts and resized across viewports, that value will grow and shrink. But it will always compute to a value within the range of `1rem` to `3rem`. 14 | 15 | Another suggested option for the middle ideal value is to use a viewport unit, like `4vw`, which works great for components such as models or setting padding on the `body`. 16 | 17 | {% endset %} 18 | 19 | {% set css %} 20 | .smol-responsive-padding { 21 | padding: 1.5rem clamp(1rem, 5%, 3rem); 22 | } 23 | {% endset %} 24 | 25 | {% set html %} 26 |
27 |

Gummi bears gummies cheesecake donut liquorice sweet roll lollipop chocolate cake macaroon. Dragée powder biscuit. Dessert topping jelly beans liquorice cake sesame snaps oat cake chocolate bar marshmallow. Cookie danish jelly-o pudding tart chocolate. Jelly sweet tiramisu fruitcake dessert muffin chocolate cake dragée. Donut dragée carrot cake icing. Macaroon lemon drops muffin.

28 |
29 | {% endset %} 30 | 31 | {% set resourceLink %} 32 | 33 | Explore [more techniques for contextual, intrinsic spacing](https://moderncss.dev/contextual-spacing-for-intrinsic-web-design/) on ModernCSS.dev. 34 | 35 | {% endset %} 36 | 37 | {% set codepenForm %} 38 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 39 | {% endset %} 40 | 41 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-responsive-sidebar.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Responsive Sidebar Layout" 4 | categories: ["grid", "layout"] 5 | date: 2021-02-11 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | Several layers of delicious modern CSS goodness here! First, we're using `fit-content` to handle the sidebar sizing. This allows the sidebar to grow _up to_ the defined value, but only if it _needs to_, else it will use/shrink to the equivalent of `min-content`. 12 | 13 | Next, we use `minmax` for the main content. Why? Because if we only use `1fr` then eventually our sidebar and main will share 50% of the space, and we want the main area to always be wider. We also nest `min` to ask the browser to use the minimum of _either_ of the options. The result in this case is use of `50vw` on mobile-sized viewports, and `30ch` on larger viewports. And, when there's room, it also stretches to `1fr` for the _max_ part of `minmax` 🙌🏽 14 | 15 | {% endset %} 16 | 17 | {% set css %} 18 | .smol-sidebar { 19 | display: grid; 20 | grid-template-columns: fit-content(20ch) minmax(min(50vw, 30ch), 1fr); 21 | } 22 | {% endset %} 23 | 24 | {% set html %} 25 |
26 | 27 | Some sidebar content goes here 28 | 29 | Main content 30 |
31 | {% endset %} 32 | 33 | {% set codepenForm %} 34 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 35 | {% endset %} 36 | 37 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-scroll-snap.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Scroll Snap" 4 | categories: ["grid", "layout"] 5 | date: 2021-02-21 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | 11 | {% set description %} 12 | 13 | Modern CSS has gifted us a series of properties that enable setting up more controlled scrolling experiences. In this demo, you'll find that as you begin to scroll, the middle items "snap" to the center of the scrollable area. Additionally, you are unable to scroll past more than one item at a time. 14 | 15 | To align the scroll items, we're using grid and updating the orientation of child items using `grid-auto-flow: column`. Then the width of the grid children is set using `min()` which selects the _minimum computed value_ between the options provided. The selected width options in this demo results in a large section of neighboring items being visible in the scrollable area for large viewports, while on smaller viewports the scrollable area is mostly consumed by the current scroll item. 16 | 17 | _While this is a very cool feature set, use with care!_ Be sure to test your implementation to ensure its not inaccessible. Test across a variety of devices, and with desktop zoom particularly at levels of 200% and 400% to check for overlap and how a changed aspect ratio affects scroll items. Try it out with a screen reader and make sure you can navigate to all content. 18 | 19 | **Note**: Have caution when attempting to mix fullscreen scroll snap slideshows followed by normal flow content. This can damage the overall scrolling experience and even prevent access to content. Fullscreen scroll areas are also prone to issues for users of high desktop zoom due to high risk of overlapping content as the aspect ratio changes. In addition, fullscreen versions that use `y mandatory` result in "scroll hijacking" which can be frustrating to users. 20 | 21 | Also - you may have a pleasant smooth scroll experience on a touchpad or magic mouse. But mouse users who rely on interacting with the scroll bar arrows or use a click wheel can have a jarring experience. This is due to browser and OS inconsistencies in handling the snapping based on input method (an issue was specifically reported for this demo using Chrome and Edge on PC). 22 | 23 | {% endset %} 24 | 25 | {% set css %} 26 | .smol-scroll-snap { 27 | /* Set up container positioning */ 28 | display: grid; 29 | grid-auto-flow: column; 30 | grid-gap: 1.5rem; 31 | /* Enable overflow along our scroll axis */ 32 | overflow-x: auto; 33 | /* Define axis and scroll type, where 34 | `mandatory` means any scroll attempt will 35 | cause a scroll to the next item */ 36 | scroll-snap-type: x mandatory; 37 | padding: 0 0 1.5rem; 38 | -webkit-overflow-scrolling: touch; 39 | } 40 | 41 | .smol-scroll-snap > * { 42 | width: min(45ch, 60vw); 43 | /* Choose how to align children on scroll */ 44 | scroll-snap-align: center; 45 | /* Prevents scrolling past more than one child */ 46 | scroll-snap-stop: always; 47 | } 48 | {% endset %} 49 | 50 | {% set html %} 51 | 68 | {% endset %} 69 | 70 | {% set resourceLink %}{% endset %} 71 | 72 | {% set codepenForm %} 73 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 74 | {% endset %} 75 | 76 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-stack-layout.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Stack Layout" 4 | categories: ["grid", "layout"] 5 | date: 2021-02-19 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | This smol stacked layout is a grid feature that can often replace older techniques that relied on absolute positioning. It works by defining a single `grid-template-area` and then assigning all direct children to that `grid-area`. The children are then "stacked" and can take advantage of grid positioning, such as the centering technique in the demo. 12 | 13 | At first glance you might not notice, but that's a video background in the demo. And all we had to do was set `width: 100%` to ensure it filled the grid area. Then, we make use of `place-self` on the `h3` to center it. The rest is completely optional design styling! 14 | 15 | Bonus features in this demo include defining the `h3` size using `clamp()` for _viewport relative sizing_, and also using `aspect-ratio` to size the container to help reduce [cumulative layout shift](https://web.dev/cls/). 16 | 17 | {% endset %} 18 | 19 | {% set css %} 20 | .smol-stack-layout { 21 | display: grid; 22 | grid-template-areas: "stack"; 23 | /* Set within the HTML for the demo */ 24 | aspect-ratio: var(--stack-aspect-ratio); 25 | background-color: #200070; 26 | } 27 | 28 | .smol-stack-layout > * { 29 | grid-area: stack; 30 | } 31 | 32 | .smol-stack-layout video { 33 | width: 100%; 34 | } 35 | 36 | .smol-stack-layout h3 { 37 | place-self: center; 38 | font-size: clamp(2.5rem, 5vw, 5rem); 39 | text-align: center; 40 | line-height: 1; 41 | font-style: italic; 42 | padding: 5vh 2vw; 43 | } 44 | 45 | .smol-stack-layout--video small { 46 | align-self: end; 47 | justify-self: start; 48 | padding: 0 0 0.25em 0.5em; 49 | opacity: 0.8; 50 | font-size: 0.8rem; 51 | } 52 | 53 | .smol-stack-layout h3, 54 | .smol-stack-layout small { 55 | position: relative; 56 | color: #fff; 57 | } 58 | {% endset %} 59 | 60 | {% set html %} 61 |
62 | 65 |

Into The Unknown

66 | Video from Pexels 67 |
68 | {% endset %} 69 | 70 | {% set resourceLink %} 71 | 72 | For more examples of creating smol stack layouts, review my guide to [website hero designs](https://moderncss.dev/3-popular-website-heroes-created-with-css-grid-layout/), see how it's used for [creating custom checkboxes](https://moderncss.dev/pure-css-custom-checkbox-style/), and learn to use it to [position animated image captions](https://moderncss.dev/animated-image-gallery-captions-with-bonus-ken-burns-effect/). 73 | 74 | {% endset %} 75 | 76 | {% set codepenForm %} 77 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 78 | {% endset %} 79 | 80 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-transitions.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Transitions" 4 | categories: ["utility"] 5 | date: 2021-02-21 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | 11 | {% set description %} 12 | 13 | This set of performant CSS transition utility classes include CSS custom properties for scaling the transition property and duration. We're doing a few things in this demo that you may want to keep in mind if you use them. 14 | 15 | First, we're triggering the transition of the _child elements_ on `:hover` of the parent. The reason for this is that for transitions that move the element, it could end up moving out from under the mouse and causing a flicker between states. The `rise` transition is particularly in danger of that behavior. 16 | 17 | Second, we wrap our effect class in a media query check for `prefers-reduced-motion: reduce` that instantly jumps the transition to the final state. This is to comply with the request for reduced motion by effectively disabling the animated part of the transition. 18 | 19 | {% endset %} 20 | 21 | {% set css %} 22 | .smol-transitions > * { 23 | --transition-property: transform; 24 | --transition-duration: 180ms; 25 | 26 | transition: var(--transition-property) var(--transition-duration) ease-in-out; 27 | } 28 | 29 | .rise:hover > * { 30 | transform: translateY(-25%); 31 | } 32 | 33 | .rotate:hover > * { 34 | transform: rotate(15deg); 35 | } 36 | 37 | .zoom:hover > * { 38 | transform: scale(1.1); 39 | } 40 | 41 | .fade > * { 42 | --transition-property: opacity; 43 | --transition-duration: 500ms; 44 | } 45 | 46 | .fade:hover > * { 47 | opacity: 0; 48 | } 49 | 50 | @media (prefers-reduced-motion: reduce) { 51 | .smol-transitions > * { 52 | --transition-duration: 0.01ms; 53 | } 54 | } 55 | {% endset %} 56 | 57 | {% set html %} 58 | 64 | {% endset %} 65 | 66 | {% set resourceLink %}{% endset %} 67 | 68 | {% set codepenForm %} 69 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html, 'flex' %} 70 | {% endset %} 71 | 72 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-unbreakable-boxes.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Flexible Unbreakable Boxes" 4 | categories: ["component", "layout"] 5 | date: 2021-04-09 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set description %} 10 | 11 | [CSS is awesome](https://css-tricks.com/css-is-in-fact-awesome/), and using a mix of older and modern CSS we can quickly define flexible, unbreakable boxes! 12 | 13 | This demo of a `blockquote` first reuses our [responsive padding](#smol-responsive-padding) idea to enable padding that _just feels right_ as the box flexes to different sizes. The box size is controlled by setting width using the `min()` function. As the box grows and shrinks, `min()` will select the _minimum_ of the provided values, resulting in a box that has a `max-width` for large viewports _and_ a `max-width` on smaller viewports. 14 | 15 | Then we add a few properties to ensure long text values cannot break the box, including `word-break` and `hyphens` (note that [`hyphens`](https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens#browser_compatibility) may not work in all languages). 16 | 17 | Finally, the `footer` sets its width with `fit-content` just as we also used in the previous [visited styles demo](#smol-visited-styles). This makes for a great alternative to swapping to an `inline` display value in case you also need to set a `display`! 18 | 19 | {% endset %} 20 | 21 | {% set css %} 22 | .smol-unbreakable-box { 23 | --color-light: #E0D4F6; 24 | --color-dark: #675883; 25 | 26 | margin: 2rem auto; 27 | color: var(--color-dark); 28 | background-color: var(--color-light); 29 | font-size: 1.15rem; 30 | /* Smol Responsive Padding FTW! */ 31 | padding: clamp(.75rem, 3%, 2rem); 32 | /* Provide a max-width and prevent overflow */ 33 | width: min(50ch, 90%); 34 | /* Help prevent overflow of long words/names/URLs */ 35 | word-break: break-word; 36 | /* Optional, not supported for all languages */ 37 | hyphens: auto; 38 | } 39 | 40 | .smol-unbreakable-box footer { 41 | padding: 0.25em 0.5em; 42 | margin-top: 1rem; 43 | color: var(--color-light); 44 | background-color: var(--color-dark); 45 | font-size: 0.9rem; 46 | /* Creates a visual box shrunk to `max-content` */ 47 | width: fit-content; 48 | } 49 | {% endset %} 50 | 51 | {% set html %} 52 |
53 |

Topping candy canes ice cream gummi bears gingerbread marshmallow. Chocolate cake powder sugar plum topping. Cake marshmallow carrot cake. Pie liquorice liquorice sweet tootsie roll caramels donut dragée bear claw. Chocolate powder candy canes.

54 |
55 | - Captain Candy 56 |
57 |
58 | {% endset %} 59 | 60 | {% set resourceLink %} 61 | 62 | For more extensive info and another example for creating flexible, unbreakable boxes, check out this ModernCSS tutorial - [Developing For Imperfect: Future Proofing CSS Styles](https://moderncss.dev/developing-for-imperfect-future-proofing-css-styles/) 63 | 64 | {% endset %} 65 | 66 | {% set codepenForm %} 67 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 68 | {% endset %} 69 | 70 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/smol-visited-styles.njk: -------------------------------------------------------------------------------- 1 | --- 2 | meta: 3 | title: "Smol Visited Styles" 4 | categories: ["utility"] 5 | date: 2021-03-02 6 | templateEngineOverride: njk, md 7 | --- 8 | 9 | {% set resize %}false{% endset %} 10 | 11 | {% set description %} 12 | 13 | The `:visited` pseudo class is very unique because of [the potential to be exploited in terms of user's privacy](https://developer.mozilla.org/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector). To resolve this, browser makers have limited which CSS styles are allowed to be applied using `:visited`. 14 | 15 | A key gotcha is that styles applied via `:visited` will always use the parent's alpha channel - meaning, you cannot use `rgba` to go from invisible to visible, you must change the whole color value. So, to hide the initial state, you need to be able to use a solid color, such as the page or element's background color. 16 | 17 | As usual - this demo has bonus techniques and properties! Note the way we're updating the _order_ of the visited indicator using flexbox. And, we're using some newly supported properties to change the color, position, and style of the link underline. 18 | 19 | Plus, we're using `fit-content` again but as a value of `width` this time and not as a function. This means it will expand to the equivalent of `max-width` but not _exceed_ the available width, preventing overflow. 20 | 21 | {% endset %} 22 | 23 | {% set css %} 24 | ul.smol-visited-styles { 25 | --color-background: #fff; 26 | --color-accent: green; 27 | 28 | display: grid; 29 | grid-gap: 0.5rem; 30 | width: fit-content; 31 | padding: 1rem; 32 | border-radius: 0.5rem; 33 | background-color: var(--color-background); 34 | border: 1px solid var(--color-accent); 35 | } 36 | 37 | .smol-visited-styles a { 38 | display: flex; 39 | flex-direction: row-reverse; 40 | justify-content: flex-end; 41 | color: #222; 42 | text-decoration-color: var(--color-accent); 43 | text-decoration-style: dotted; 44 | text-underline-offset: 0.15em; 45 | } 46 | 47 | .smol-visited-styles a span { 48 | margin-right: 0.25em; 49 | /* Remove from normal document flow 50 | which excludes it from receiving 51 | the underline ✨ */ 52 | float: left; 53 | } 54 | 55 | .smol-visited-styles a span::after { 56 | content: "✔"; 57 | color: var(--color-background); 58 | } 59 | 60 | .smol-visited-styles a:visited span::after { 61 | color: var(--color-accent); 62 | } 63 | {% endset %} 64 | 65 | {% set html %} 66 | 71 | {% endset %} 72 | 73 | {% set resourceLink %} 74 | 75 | Una Kravets has a much more [in-depth reference on styling `:visited`](https://una.im/hacking-visited/). For another example, see how I've styled it for the [Style Stage directory](https://stylestage.dev/styles/). 76 | 77 | {% endset %} 78 | 79 | {% set codepenForm %} 80 | {% postToCodepen meta.title, page.fileSlug, meta.categories, css, html %} 81 | {% endset %} 82 | 83 | {% include "code.njk" %} -------------------------------------------------------------------------------- /src/snippets/snippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "tags": "snippets", 3 | "permalink": false 4 | } 5 | -------------------------------------------------------------------------------- /src/snippets/snippets.meta: -------------------------------------------------------------------------------- 1 | { 2 | "title": { 3 | "type": "string", 4 | "required": true 5 | }, 6 | "categories": { 7 | "type": "array", 8 | "required": true 9 | } 10 | } 11 | --------------------------------------------------------------------------------