Merge branch 'master' into master

This commit is contained in:
Angelos Chalaris
2018-10-27 11:36:19 +03:00
committed by GitHub
76 changed files with 6379 additions and 7835 deletions

16
.travis.yml Normal file
View File

@ -0,0 +1,16 @@
language: node_js
node_js:
- node
install:
- npm install
script:
- npm run build
after_script:
- test $TRAVIS_EVENT_TYPE = cron
&& echo -e "\e[95mDeploying to Repository"
&& chmod +x .travis/push.sh
&& ./.travis/push.sh
- chmod +x .travis/forcepush.sh && ./.travis/forcepush.sh
cache:
directories:
- node_modules

3
.travis/forcepush.sh Normal file
View File

@ -0,0 +1,3 @@
if [[ $TRAVIS_COMMIT_MESSAGE == *"--force-build"* ]];
then echo -e "\e[95mFORCE-DEPLOY: Deploying to Repository" && chmod +x .travis/push.sh && ./.travis/push.sh;
fi

33
.travis/push.sh Normal file
View File

@ -0,0 +1,33 @@
#!/bin/bash
setup_git() {
git config --global user.email "30secondsofcode@gmail.com"
git config --global user.name "30secondsofcode"
}
commit_website_files() {
if [ $TRAVIS_EVENT_TYPE != "pull_request" ]; then
if [ $TRAVIS_BRANCH == "master" ]; then
echo "Committing to master branch..."
git checkout master
git add *
if [ $TRAVIS_EVENT_TYPE == "cron" ]; then
git commit --message "Travis build: $TRAVIS_BUILD_NUMBER [cron]"
else
git commit --message "Travis build: $TRAVIS_BUILD_NUMBER [FORCED]"
fi
fi
fi
}
upload_files() {
if [ $TRAVIS_EVENT_TYPE != "pull_request" ]; then
if [ $TRAVIS_BRANCH == "master" ]; then
echo "Pushing to master branch..."
git push --force --quiet "https://${GH_TOKEN}@github.com/30-seconds/30-seconds-of-css.git" master > /dev/null 2>&1
fi
fi
}
setup_git
commit_website_files
upload_files

View File

@ -8,19 +8,19 @@ In the interest of fostering an open and welcoming environment, we as contributo
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities

View File

@ -11,22 +11,11 @@ Brief description
#### CSS
```css
```
#### Demo
<!-- You must create a `snippet-demo` parent block and use it as a namespace with BEM syntax. -->
<div class="snippet-demo">
<some-element class="snippet-demo__snippet-name"></some-element>
</div>
<!-- Add your style rules here. -->
<style>
</style>
<!-- Leave this blank, the build script will generate the demo for you. -->
#### Explanation
@ -41,6 +30,6 @@ Brief description
<!-- Whenever possible, link a `caniuse` feature which allows the browser support percentage to be displayed.
If no link is provided, it defaults to 99+%. -->
* https://caniuse.com/#feat=some-feature
- https://caniuse.com/#feat=some-feature
<!-- tags: (separate each by a comma) -->

View File

@ -1,16 +1,22 @@
# 30 Seconds of CSS
![logo](https://i.imgur.com/2L1bMyy.png)
<a href="https://30-seconds.github.io/30-seconds-of-css/" target="_blank">![logo](https://i.imgur.com/kPMfyD4.jpg)</a>
[![License](https://img.shields.io/badge/license-CC0--1.0-blue.svg)](https://github.com/atomiks/30-seconds-of-css/blob/master/LICENSE) [![Gitter chat](https://img.shields.io/badge/chat-on%20gitter-4FB999.svg)](https://gitter.im/30-seconds-of-css/Lobby) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) [![Insight.io](https://img.shields.io/badge/insight.io-Ready-brightgreen.svg)](https://insight.io/github.com/atomiks/30-seconds-of-css/tree/master/?source=0)
[![License](https://img.shields.io/badge/license-CC0--1.0-blue.svg)](https://github.com/30-seconds/30-seconds-of-css/blob/master/LICENSE) [![Gitter chat](https://img.shields.io/badge/chat-on%20gitter-4FB999.svg)](https://gitter.im/30-seconds-of-css/Lobby) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) [![Insight.io](https://img.shields.io/badge/insight.io-Ready-brightgreen.svg)](https://insight.io/github.com/30-seconds/30-seconds-of-css/tree/master/?source=0)
A curated collection of useful CSS snippets you can understand in 30 seconds or less.
Inspired by [30 seconds of code](https://github.com/Chalarangelo/30-seconds-of-code).
## View online
https://atomiks.github.io/30-seconds-of-css/
https://30-seconds.github.io/30-seconds-of-css/
## Contributing
See CONTRIBUTING.md for the snippet template.
#### Related projects
- [30 Seconds of code](https://30secondsofcode.org/)
- [30 Seconds of Interviews](https://30secondsofinterviews.org/)
- [30 Seconds of React](https://github.com/30-seconds/30-seconds-of-react)

View File

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
docs/blob.9c6ecde4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

File diff suppressed because one or more lines are too long

32
docs/js.5edae55e.js Normal file

File diff suppressed because one or more lines are too long

1
docs/js.5edae55e.map Normal file

File diff suppressed because one or more lines are too long

9
docs/js.6f9801cd.css Normal file

File diff suppressed because one or more lines are too long

1
docs/leaves.dcfeae1d.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

1
docs/new.cdde38b9.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

1359
index.html

File diff suppressed because it is too large Load Diff

10254
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,9 @@
"description": "A curated collection of useful CSS snippets.",
"main": "index.js",
"scripts": {
"dev": "nodemon -e md,js ./scripts/build.js & parcel",
"dev": "nodemon -e md,js ./scripts/build.js & parcel index.html",
"build": "node ./scripts/build.js && npm run prettier && npm run parcel",
"parcel": "parcel build index.html -d docs/ --public-url ./",
"parcel": "npx rimraf docs && parcel build index.html -d docs/ --public-url ./",
"prettier": "prettier --write \"**/*.{js,json,md,css,scss}\""
},
"author": "atomiks",
@ -21,18 +21,21 @@
"babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "^6.24.1",
"caniuse-db": "^1.0.30000813",
"date-fns": "^1.29.0",
"jsdom": "^11.6.2",
"marked": "^0.3.16",
"node-sass": "^4.7.2",
"nodemon": "^1.15.1",
"node-sass": "^4.9.3",
"nodemon": "^1.18.4",
"normalize.css": "^8.0.0",
"parcel-bundler": "^1.6.2",
"prettier": "^1.10.2",
"parcel-bundler": "^1.9.7",
"prettier": "^1.14.3",
"pretty": "^2.0.0",
"prismjs": "^1.11.0"
"prismjs": "^1.11.0",
"rimraf": "^2.6.2"
},
"dependencies": {
"feather-icons": "^4.7.0",
"focus-visible": "^4.1.0"
"focus-visible": "^4.1.0",
"jump.js": "^1.0.2"
}
}

View File

@ -3,7 +3,9 @@ const path = require('path')
const marked = require('marked')
const pretty = require('pretty')
const caniuseDb = require('caniuse-db/data.json')
const { toKebabCase, createElement, template, dom } = require('../utils/utils.js')
const sass = require('node-sass')
const { toKebabCase, createElement, template, dom, getCode } = require('../utils/utils.js')
const { differenceInDays } = require('date-fns')
const SNIPPETS_PATH = './snippets'
const TAGS = [
@ -69,7 +71,23 @@ TAGS.slice(1).forEach(tag => {
for (const snippetFile of fs.readdirSync(SNIPPETS_PATH)) {
const snippetPath = path.join(SNIPPETS_PATH, snippetFile)
const snippetData = fs.readFileSync(snippetPath, 'utf8')
const markdown = marked(snippetData, { renderer })
const html = getCode('html', snippetData).trim()
const css = getCode('css', snippetData)
const scopedCSS = sass.renderSync({
data: `[data-scope="${snippetFile}"] { ${css} }`
})
const js = getCode('js', snippetData)
const demo =
`<div class="snippet-demo" data-scope="${snippetFile}">${html}</div>` +
`<style>${scopedCSS.css.toString()}</style>` +
`${js ? `<script>(function(){${js}})();</script>` : ''}`
const markdown = marked(snippetData, { renderer }).replace(
'<h4>Demo</h4>',
`<h4>Demo</h4>${demo}`
)
const snippetEl = createElement(`<div class="snippet">${markdown}</div>`)
snippetContainer.append(snippetEl)
@ -98,6 +116,21 @@ for (const snippetFile of fs.readdirSync(SNIPPETS_PATH)) {
}</a>`
)
// new icon = less than 31 days old
const date = (snippetData.match(/<!--\s*date:\s*(.+?)-->/) || [, ''])[1]
if (date && differenceInDays(new Date(date), new Date()) < 31) {
snippetEl.prepend(
createElement(
'<img alt="New" draggable="false" class="snippet__new" src="./src/img/new.svg">'
)
)
link.prepend(
createElement(
'<img alt="New" draggable="false" class="sidebar__new" src="./src/img/new.svg">'
)
)
}
// tags
const tags = (snippetData.match(/<!--\s*tags:\s*(.+?)-->/) || [, ''])[1]
.split(/,\s*/)

View File

@ -47,45 +47,6 @@ Creates a bouncing loader animation.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
</div>
<style>
@keyframes bouncing-loader {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0.1;
transform: translateY(-1rem);
}
}
.snippet-demo__bouncing-loader {
display: flex;
justify-content: center;
}
.snippet-demo__bouncing-loader > div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.snippet-demo__bouncing-loader > div:nth-child(2) {
animation-delay: 0.2s;
}
.snippet-demo__bouncing-loader > div:nth-child(3) {
animation-delay: 0.4s;
}
</style>
#### Explanation
Note: `1rem` is usually `16px`.
@ -110,6 +71,6 @@ Note: `1rem` is usually `16px`.
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-animation
- https://caniuse.com/#feat=css-animation
<!-- tags: animation -->

View File

@ -2,38 +2,40 @@
Resets the box-model so that `width`s and `height`s are not affected by their `border`s or `padding`.
#### HTML
```html
<div class="box">border-box</div>
<div class="box content-box">content-box</div>
```
#### CSS
```css
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
.box {
display: inline-block;
width: 150px;
height: 150px;
padding: 10px;
background: tomato;
color: white;
border: 10px solid red;
}
.content-box {
box-sizing: content-box;
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__box-sizing-reset">Demo</div>
</div>
<style>
.snippet-demo__box-sizing-reset {
box-sizing: border-box;
width: 200px;
padding: 1.5em;
color: #7983ff;
font-family: sans-serif;
background-color: white;
border: 5px solid;
}
</style>
#### Explanation
1. `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.
@ -43,6 +45,6 @@ html {
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css3-boxsizing
- https://caniuse.com/#feat=css3-boxsizing
<!-- tags: layout -->

View File

@ -21,19 +21,6 @@ Creates a circle shape with pure CSS.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__circle"></div>
</div>
<style>
.snippet-demo__circle {
border-radius: 50%;
width: 2rem;
height: 2rem;
background: #333;
}
</style>
#### Explanation
`border-radius: 50%` curves the borders of an element to create a circle.
@ -45,6 +32,6 @@ values will create an ellipse.
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=border-radius
- https://caniuse.com/#feat=border-radius
<!-- tags: visual -->

View File

@ -30,26 +30,6 @@ Ensures that an element self-clears its children.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__clearfix">
<div class="snippet-demo__floated">float a</div>
<div class="snippet-demo__floated">float b</div>
<div class="snippet-demo__floated">float c</div>
</div>
</div>
<style>
.snippet-demo__clearfix::after {
content: '';
display: block;
clear: both;
}
.snippet-demo__floated {
float: left;
}
</style>
#### Explanation
1. `.clearfix::after` defines a pseudo-element.

View File

@ -18,7 +18,6 @@ Given an element of variable width, it will ensure its height remains proportion
}
.constant-width-to-height-ratio::before {
content: '';
display: block;
padding-top: 100%;
float: left;
}
@ -31,30 +30,6 @@ Given an element of variable width, it will ensure its height remains proportion
#### Demo
Resize your browser window to see the proportion of the element remain the same.
<div class="snippet-demo">
<div class="snippet-demo__constant-width-to-height-ratio"></div>
</div>
<style>
.snippet-demo__constant-width-to-height-ratio {
background: #333;
width: 50%;
}
.snippet-demo__constant-width-to-height-ratio::before {
content: '';
display: block;
padding-top: 100%;
float: left;
}
.snippet-demo__constant-width-to-height-ratio::after {
content: '';
display: block;
clear: both;
}
</style>
#### Explanation
`padding-top` on the `::before` pseudo-element causes the height of the element to equal a percentage of

57
snippets/counter.md Normal file
View File

@ -0,0 +1,57 @@
### Counter
Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.
#### HTML
```html
<ul>
<li>List item</li>
<li>List item</li>
<li>
List item
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
</li>
</ul>
```
#### CSS
```css
ul {
counter-reset: counter;
}
li::before {
counter-increment: counter;
content: counters(counter, '.') ' ';
}
```
#### Demo
#### Explanation
You can create a ordered list using any type of HTML.
1. `counter-reset` Initializes a counter, the value is the name of the counter. By default, the counter starts in 0. This property can also be used to change its value to any specific number.
2. `counter-increment` Used in element that will be countable. Once `counter-reset` initialized, a counter's value can be increased or decreased.
3. `counter(name, style)` Displays the value of a section counter. Generally used in a `content` property. This function can receive two parameters, the first as the name of the counter and the second one can be `decimal` or `upper-roman` (`decimal` by default).
4. `counters(counter, string, style)` Displays the value of a section counter. Generally used in a `content` property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be `decimal` or `upper-roman` (`decimal` by default).
5. A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the `counters()` function, separating text can be inserted between different levels of nested counters.
#### Browser support
<span class="snippet__support-note">✅ No caveats.</span>
- https://caniuse.com/#feat=css-counters
<!-- tags: visual, other -->

View File

@ -6,79 +6,54 @@ Customizes the scrollbar style for the document and elements with scrollable ove
```html
<div class="custom-scrollbar">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.<br>
Iure id exercitationem nulla qui repellat laborum vitae, <br>
molestias tempora velit natus. Quas, assumenda nisi. <br>
Quisquam enim qui iure, consequatur velit sit?
</p>
</div>
```
#### CSS
```css
/* Document scrollbar */
::-webkit-scrollbar {
.custom-scrollbar {
height: 70px;
overflow-y: scroll;
}
/* To style the document scrollbar, remove `.custom-scrollbar` */
.custom-scrollbar::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
.custom-scrollbar::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
.custom-scrollbar::-webkit-scrollbar-thumb {
border-radius: 10px;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
/* Scrollable element */
.some-element::webkit-scrollbar {
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__custom-scrollbar">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?
</p>
</div>
</div>
<style>
.snippet-demo__custom-scrollbar {
height: 100px;
overflow: auto;
}
.snippet-demo__custom-scrollbar::-webkit-scrollbar {
width: 8px;
}
.snippet-demo__custom-scrollbar::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
.snippet-demo__custom-scrollbar::-webkit-scrollbar-thumb {
border-radius: 10px;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
</style>
#### Explanation
1. `::-webkit-scrollbar` targets the whole scrollbar element.
2. `::-webkit-scrollbar-track` targets only the scrollbar track.
3. `::-webkit-scrollbar-thumb` targets the scrollbar thumb.
There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/)
There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/).
#### Browser support
<span class="snippet__support-note">⚠️ Scrollbar styling doesn't appear to be on any standards track.</span>
* https://caniuse.com/#feat=css-scrollbar
- https://caniuse.com/#feat=css-scrollbar
<!-- tags: visual -->

View File

@ -23,21 +23,6 @@ Changes the styling of text selection.
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__custom-text-selection">Select some of this text.</p>
</div>
<style>
.snippet-demo__custom-text-selection::selection {
background: deeppink;
color: white;
}
.snippet-demo__custom-text-selection::-moz-selection {
background: deeppink;
color: white;
}
</style>
#### Explanation
`::selection` defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.
@ -47,6 +32,6 @@ Changes the styling of text selection.
<span class="snippet__support-note">⚠️ Requires prefixes for full support and is not actually
in any specification.</span>
* https://caniuse.com/#feat=css-selection
- https://caniuse.com/#feat=css-selection
<!-- tags: visual -->

View File

@ -12,13 +12,14 @@ CSS variables that contain specific values to be reused throughout a document.
```css
:root {
/* Place variables within here to use the variables globally. */
}
.custom-variables {
--some-color: #da7800;
--some-keyword: italic;
--some-size: 1.25em;
--some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;
}
.custom-variables {
color: var(--some-color);
font-size: var(--some-size);
font-style: var(--some-keyword);
@ -28,28 +29,6 @@ CSS variables that contain specific values to be reused throughout a document.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__custom-variables">
<p>CSS is awesome!</p>
</div>
</div>
<style>
.snippet-demo__custom-variables {
--some-color: #686868;
--some-keyword: italic;
--some-size: 1.25em;
--some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray , 0 0 0.2em slategray;
}
.snippet-demo__custom-variables p {
color: var(--some-color);
font-size: var(--some-size);
font-style: var(--some-keyword);
text-shadow: var(--some-complex-value);
}
</style>
#### Explanation
The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document. Variables can also be scoped to a selector if defined within the block.
@ -62,6 +41,6 @@ Reuse variables throughout the document using the `var(--variable-name)` functio
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-variables
- https://caniuse.com/#feat=css-variables
<!-- tags: other -->

View File

@ -19,17 +19,6 @@ Makes the content unselectable.
#### Demo
<div class="snippet-demo">
<p>You can select me.</p>
<p class="snippet-demo__disable-selection">You can't select me!</p>
</div>
<style>
.snippet-demo__disable-selection {
user-select: none;
}
</style>
#### Explanation
`user-select: none` specifies that the text cannot be selected.
@ -39,6 +28,6 @@ Makes the content unselectable.
<span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
<span class="snippet__support-note">⚠️ This is not a secure method to prevent users from copying content.</span>
* https://caniuse.com/#feat=user-select-none
- https://caniuse.com/#feat=user-select-none
<!-- tags: interactivity -->

View File

@ -0,0 +1,55 @@
### Display table centering
Vertically and horizontally centers a child element within its parent element using `display: table` (as an alternative to `flexbox`).
#### HTML
```html
<div class="container">
<div class="center">
<span>Centered content</span>
</div>
</div>
```
#### CSS
```css
.container {
border: 1px solid #333;
height: 250px;
width: 250px;
}
.center {
display: table;
height: 100%;
width: 100%;
}
.center > span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
```
#### Demo
#### Explanation
1. `display: table` on '.center' allows the element to behave like a `<table>` HTML element.
2. 100% height and width on '.center' allows the element to fill the available space within its parent element.
3. `display: table-cell` on '.center > span' allows the element to behave like an <td> HTML element.
4. `text-align: center` on '.center > span' centers the child element horizontally.
5. `vertical-align: middle` on '.center > span' centers the child element vertically.
The outer parent ('.container' in this case) must have a fixed height and width.
#### Browser support
<span class="snippet__support-note">✅ No caveats.</span>
- https://caniuse.com/#search=display%3A%20table
<!-- tags: layout -->

View File

@ -32,26 +32,6 @@ Creates a donut spinner that can be used to indicate the loading of content.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__donut-spinner"></div>
</div>
<style>
@keyframes snippet-demo__donut-spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg);}
}
.snippet-demo__donut-spinner {
display: inline-block;
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #7983ff;
border-radius: 50%;
width: 30px;
height: 30px;
animation: snippet-demo__donut-spin 1.2s linear infinite;
}
</style>
#### Explanation
Use a semi-transparent `border` for the whole element, except one side that will
@ -61,7 +41,7 @@ serve as the loading indicator for the donut. Use `animation` to rotate the elem
<span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
* https://caniuse.com/#feat=css-animation
* https://caniuse.com/#feat=transforms2d
- https://caniuse.com/#feat=css-animation
- https://caniuse.com/#feat=transforms2d
<!-- tags: animation -->

View File

@ -5,23 +5,18 @@ Creates a shadow similar to `box-shadow` but based on the colors of the element
#### HTML
```html
<div class="dynamic-shadow-parent">
<div class="dynamic-shadow"></div>
</div>
```
#### CSS
```css
.dynamic-shadow-parent {
position: relative;
z-index: 1;
}
.dynamic-shadow {
position: relative;
width: 10rem;
height: 10rem;
background: linear-gradient(75deg, #6d78ff, #00ffb8);
z-index: 1;
}
.dynamic-shadow::after {
content: '';
@ -38,57 +33,23 @@ Creates a shadow similar to `box-shadow` but based on the colors of the element
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__dynamic-shadow-parent">
<div class="snippet-demo__dynamic-shadow"></div>
</div>
</div>
<style>
.snippet-demo__dynamic-shadow-parent {
position: relative;
z-index: 1;
}
.snippet-demo__dynamic-shadow {
position: relative;
width: 10rem;
height: 10rem;
background: linear-gradient(75deg, #6d78ff, #00ffb8);
}
.snippet-demo__dynamic-shadow::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background: inherit;
top: 0.5rem;
filter: blur(0.4rem);
opacity: 0.7;
z-index: -1;
}
</style>
#### Explanation
The snippet requires a somewhat complex case of stacking contexts to get right, such that the pseudo-element
will be positioned underneath the element itself while still being visible.
1. `position: relative` on the parent establishes a Cartesian positioning context for child elements.
1. `position: relative` on the element establishes a Cartesian positioning context for psuedo-elements.
2. `z-index: 1` establishes a new stacking context.
3. `position: relative` on the child establishes a positioning context for pseudo-elements.
4. `::after` defines a pseudo-element.
5. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
6. `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.
7. `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.
8. `top: 0.5rem` offsets the pseudo-element down slightly from its parent.
9. `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.
10. `opacity: 0.7` makes the pseudo-element partially transparent.
11. `z-index: -1` positions the pseudo-element behind the parent.
3. `::after` defines a pseudo-element.
4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
5. `width: 100%` and `height: 100%` sizes the pseudo-element to fill its parent's dimensions, making it equal in size.
6. `background: inherit` causes the pseudo-element to inherit the linear gradient specified on the element.
7. `top: 0.5rem` offsets the pseudo-element down slightly from its parent.
8. `filter: blur(0.4rem)` will blur the pseudo-element to create the appearance of a shadow underneath.
9. `opacity: 0.7` makes the pseudo-element partially transparent.
10. `z-index: -1` positions the pseudo-element behind the parent but in front of the background.
#### Browser support
<span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
* https://caniuse.com/#feat=css-filters
- https://caniuse.com/#feat=css-filters
<!-- tags: visual -->

View File

@ -6,13 +6,17 @@ powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.
#### HTML
```html
<div class="easing-variables"></div>
<div class="easing-variables">Hover</div>
```
#### CSS
```css
:root {
/* Place variables in here to use globally */
}
.easing-variables {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
@ -33,11 +37,13 @@ powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.
--ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
--ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
--ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
}
.easing-variables {
width: 50px;
height: 50px;
display: inline-block;
width: 75px;
height: 75px;
padding: 10px;
color: white;
line-height: 50px;
text-align: center;
background: #333;
transition: transform 1s var(--ease-out-quart);
}
@ -49,52 +55,6 @@ powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__easing-variables">Hover</div>
</div>
<style>
:root {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
--ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
--ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
--ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
--ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
--ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
--ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
--ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);
--ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
--ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);
--ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
--ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
--ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
--ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
}
.snippet-demo__easing-variables {
width: 75px;
height: 75px;
background: #333;
color: white;
font-size: 0.8rem;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
transition: transform 1s var(--ease-out-quart);
}
.snippet-demo__easing-variables:hover {
transform: rotate(45deg);
}
</style>
#### Explanation
The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document. In HTML, `:root` represents the `<html>` element and is identical to the selector `html`, except that its specificity is higher.
@ -103,6 +63,6 @@ The variables are defined globally within the `:root` CSS pseudo-class which mat
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-variables
- https://caniuse.com/#feat=css-variables
<!-- tags: animation -->

View File

@ -21,19 +21,6 @@ Creates an effect where text appears to be "etched" or engraved into the backgro
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__etched-text">I appear etched into the background.</p>
</div>
<style>
.snippet-demo__etched-text {
font-size: 1.5rem;
font-weight: bold;
color: #b8bec5;
text-shadow: 0 2px 0 white;
}
</style>
#### Explanation
`text-shadow: 0 2px white` creates a white shadow offset `0px` horizontally and `2px` vertically
@ -48,6 +35,6 @@ of the background.
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-textshadow
- https://caniuse.com/#feat=css-textshadow
<!-- tags: visual -->

View File

@ -23,22 +23,6 @@ Evenly distributes child elements within a parent element.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__evenly-distributed-children">
<p>Item1</p>
<p>Item2</p>
<p>Item3</p>
</div>
</div>
<style>
.snippet-demo__evenly-distributed-children {
display: flex;
width: 100%;
justify-content: space-between;
}
</style>
#### Explanation
1. `display: flex` enables flexbox.
@ -50,6 +34,6 @@ Alternatively, use `justify-content: space-around` to distribute the children wi
<span class="snippet__support-note">⚠️ Needs prefixes for full support.</span>
* https://caniuse.com/#feat=flexbox
- https://caniuse.com/#feat=flexbox
<!-- tags: layout -->

View File

@ -17,26 +17,12 @@ Horizontally and vertically centers a child element within a parent element usin
display: flex;
justify-content: center;
align-items: center;
height: 100px;
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__flexbox-centering">
<p class="snippet-demo__flexbox-centering__child">Centered content.</p>
</div>
</div>
<style>
.snippet-demo__flexbox-centering {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
}
</style>
#### Explanation
1. `display: flex` enables flexbox.
@ -47,6 +33,6 @@ Horizontally and vertically centers a child element within a parent element usin
<span class="snippet__support-note">⚠️ Needs prefixes for full support.</span>
* https://caniuse.com/#feat=flexbox
- https://caniuse.com/#feat=flexbox
<!-- tags: layout -->

View File

@ -20,23 +20,6 @@ Gives text a gradient color.
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__gradient-text">
Gradient text
</p>
</div>
<style>
.snippet-demo__gradient-text {
background: -webkit-linear-gradient(pink, red);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
font-size: 2rem;
font-weight: bold;
margin: 0;
}
</style>
#### Explanation
1. `background: -webkit-linear-gradient(...)` gives the text element a gradient background.
@ -48,6 +31,6 @@ Gives text a gradient color.
<span class="snippet__support-note">⚠️ Uses non-standard properties.</span>
* https://caniuse.com/#feat=text-stroke
- https://caniuse.com/#feat=text-stroke
<!-- tags: visual -->

View File

@ -17,26 +17,12 @@ Horizontally and vertically centers a child element within a parent element usin
display: grid;
justify-content: center;
align-items: center;
height: 100px;
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__grid-centering">
<p class="snippet-demo__grid-centering__child">Centered content.</p>
</div>
</div>
<style>
.snippet-demo__grid-centering {
display: grid;
justify-content: center;
align-items: center;
height: 200px;
}
</style>
#### Explanation
1. `display: grid` enables grid.
@ -47,6 +33,6 @@ Horizontally and vertically centers a child element within a parent element usin
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-grid
- https://caniuse.com/#feat=css-grid
<!-- tags: layout -->

View File

@ -1,109 +0,0 @@
### Grid layout
Basic website layout using `grid`.
#### HTML
```html
<div class="grid-layout">
<div class="header">Header</div>
<div class="sidebar">Sidebar</div>
<div class="content">
Content
<br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="footer">Footer</div>
</div>
```
#### CSS
```css
.grid-layout {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(3, 1fr);
grid-template-areas:
'sidebar header header'
'sidebar content content'
'sidebar footer footer';
color: white;
}
.grid-layout > div {
background: #333;
padding: 10px;
}
.sidebar {
grid-area: sidebar;
}
.content {
grid-area: content;
}
.header {
grid-area: header;
}
.footer {
grid-area: footer;
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__grid-layout">
<div class="box snippet-demo__grid-layout__header">Header</div>
<div class="box snippet-demo__grid-layout__sidebar">Sidebar</div>
<div class="box snippet-demo__grid-layout__content">Content
<br> Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="box snippet-demo__grid-layout__footer">Footer</div>
</div>
</div>
<style>
.snippet-demo__grid-layout {
margin: 1em;
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(3, 1fr);
grid-template-areas:
"sidebar header header"
"sidebar content content"
"sidebar footer footer";
background-color: #fff;
color: white;
}
.snippet-demo__grid-layout > div {
background: #333;
padding: 10px;
}
.snippet-demo__grid-layout__sidebar {
grid-area: sidebar;
}
.snippet-demo__grid-layout__content {
grid-area: content;
}
.snippet-demo__grid-layout__header {
grid-area: header;
}
.snippet-demo__grid-layout__footer {
grid-area: footer;
}
</style>
#### Explanation
1. `display: grid` enables grid.
2. `grid-gap: 10px` defines spacing between the elements.
3. `grid-template-columns: repeat(3, 1fr)` defines 3 columns of the same size.
4. `grid-template-areas` defines the names of grid areas.
5. `grid-area: sidebar` makes the element use the area with the name `sidebar`.
#### Browser support
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-grid
<!-- tags: layout -->

View File

@ -37,34 +37,6 @@ very sharp and crisp.
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__hairline-border">Text with a hairline border around it.</p>
</div>
<style>
.snippet-demo__hairline-border {
box-shadow: 0 0 0 1px;
}
@media (min-resolution: 2dppx) {
.snippet-demo__hairline-border {
box-shadow: 0 0 0 0.5px;
}
}
@media (min-resolution: 3dppx) {
.snippet-demo__hairline-border {
box-shadow: 0 0 0 0.33333333px;
}
}
@media (min-resolution: 4dppx) {
.snippet-demo__hairline-border {
box-shadow: 0 0 0 0.25px;
}
}
</style>
#### Explanation
1. `box-shadow`, when only using spread, adds a pseudo-border which can use subpixels\*.
@ -75,8 +47,8 @@ very sharp and crisp.
<span class="snippet__support-note">⚠️ Needs alternate syntax and JavaScript user agent checking for full support.</span>
* https://caniuse.com/#feat=css-boxshadow
* https://caniuse.com/#feat=css-media-resolution
- https://caniuse.com/#feat=css-boxshadow
- https://caniuse.com/#feat=css-media-resolution
<hr>

View File

@ -0,0 +1,65 @@
### Height transition
Transitions an element's height from `0` to `auto` when its height is unknown.
#### HTML
```html
<div class="trigger">
Hover me to see a height transition.
<div class="el">content</div>
</div>
```
#### CSS
```css
.el {
transition: max-height 0.5s;
overflow: hidden;
max-height: 0;
}
.trigger:hover > .el {
max-height: var(--max-height);
}
```
#### JavaScript
```js
var el = document.querySelector('.el')
var height = el.scrollHeight
el.style.setProperty('--max-height', height + 'px')
```
#### Demo
#### Explanation
##### CSS
1. `transition: max-height: 0.5s cubic-bezier(...)` specifies that changes to `max-height` should be transitioned over 0.5 seconds, using an `ease-out-quint` timing function.
2. `overflow: hidden` prevents the contents of the hidden element from overflowing its container.
3. `max-height: 0` specifies that the element has no height initially.
4. `.target:hover > .el` specifies that when the parent is hovered over, target a child `.el` within
it and use the `--max-height` variable which was defined by JavaScript.
##### JavaScript
1. `el.scrollHeight` is the height of the element including overflow, which will change dynamically
based on the content of the element.
2. `el.style.setProperty(...)` sets the `--max-height` CSS variable which is used to specify the `max-height` of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.
#### Browser Support
<div class="snippet__requires-javascript">Requires JavaScript</div>
<span class="snippet__support-note">
⚠️ Causes reflow on each animation frame, which will be laggy if there are a large number of elements
beneath the element that is transitioning in height.
</span>
- https://caniuse.com/#feat=css-variables
- https://caniuse.com/#feat=css-transitions
<!-- tags: animation -->

View File

@ -38,34 +38,6 @@ Creates an animated underline effect when the text is hovered over.
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__hover-underline-animation">Hover this text to see the effect!</p>
</div>
<style>
.snippet-demo__hover-underline-animation {
display: inline-block;
position: relative;
color: #0087ca;
}
.snippet-demo__hover-underline-animation::after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: #0087ca;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.snippet-demo__hover-underline-animation:hover::after {
transform: scaleX(1);
transform-origin: bottom left;
}
</style>
#### Explanation
1. `display: inline-block` makes the block `p` an `inline-block` to prevent the underline from
@ -87,7 +59,7 @@ Creates an animated underline effect when the text is hovered over.
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=transforms2d
* https://caniuse.com/#feat=css-transitions
- https://caniuse.com/#feat=transforms2d
- https://caniuse.com/#feat=css-transitions
<!-- tags: animation -->

View File

@ -0,0 +1,54 @@
### Last item with remaining available height
Take advantage of available viewport space by giving the last element the remaining available space in current viewport, even when resizing the window.
#### HTML
```html
<div class="container">
<div>Div 1</div>
<div>Div 2</div>
<div>Div 3</div>
</div>
```
#### CSS
```css
html,
body {
height: 100%;
margin: 0;
}
.container {
height: 100%;
display: flex;
flex-direction: column;
}
.container > div:last-child {
background-color: tomato;
flex: 1;
}
```
#### Demo
#### Explanation
1. `height: 100%` set the height of container as viewport height.
2. `display: flex` enables flexbox.
3. `flex-direction: column` set the direction of flex items' order from top to down.
4. `flex-grow: 1` the flexbox will apply remaining available space of container to last child element.
The parent must have a viewport height. `flex-grow: 1` could be applied to the first or second element, which will have all available space.
#### Browser support
<span class="snippet__support-note">⚠️ Needs prefixes for full support.</span>
- https://caniuse.com/#feat=flexbox
<!-- tags: layout -->
<!-- date: 2018-09-30 -->

View File

@ -54,8 +54,8 @@ A hover effect where the gradient follows the mouse cursor.
```js
var btn = document.querySelector('.mouse-cursor-gradient-tracking')
btn.onmousemove = function(e) {
var x = e.pageX - btn.offsetLeft
var y = e.pageY - btn.offsetTop
var x = e.pageX - btn.offsetLeft - btn.offsetParent.offsetLeft
var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
btn.style.setProperty('--x', x + 'px')
btn.style.setProperty('--y', y + 'px')
}
@ -63,78 +63,15 @@ btn.onmousemove = function(e) {
#### Demo
<div class="snippet-demo">
<button class="snippet-demo__mouse-cursor-gradient-tracking">
<span>Hover me</span>
</button>
</div>
<style>
.snippet-demo__mouse-cursor-gradient-tracking {
position: relative;
background: #7983ff;
padding: 0.5rem 1rem;
font-size: 1.2rem;
border: none;
color: white;
cursor: pointer;
outline: none;
overflow: hidden;
}
.snippet-demo__mouse-cursor-gradient-tracking span {
position: relative;
}
.snippet-demo__mouse-cursor-gradient-tracking::before {
--size: 0;
content: '';
position: absolute;
left: var(--x);
top: var(--y);
width: var(--size);
height: var(--size);
background: radial-gradient(circle closest-side, aqua, rgba(0,255,255,0.0001));
transform: translate(-50%, -50%);
transition: width .2s ease, height .2s ease;
}
.snippet-demo__mouse-cursor-gradient-tracking:hover::before {
--size: 200px;
}
</style>
<script>
(function () {
var btn = document.querySelector('.snippet-demo__mouse-cursor-gradient-tracking')
btn.onmousemove = function (e) {
var x = e.pageX - btn.offsetLeft - btn.offsetParent.offsetLeft
var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
btn.style.setProperty('--x', x + 'px')
btn.style.setProperty('--y', y + 'px')
}
})()
</script>
#### Explanation
_TODO_
**Note!**
If the element's parent has a positioning context (`position: relative`), you will need to subtract
its offsets as well.
```js
var x = e.pageX - btn.offsetLeft - btn.offsetParent.offsetLeft
var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
```
#### Browser support
<div class="snippet__requires-javascript">Requires JavaScript</div>
<span class="snippet__support-note">⚠️ Requires JavaScript.</span>
* https://caniuse.com/#feat=css-variables
- https://caniuse.com/#feat=css-variables
<!-- tags: visual, interactivity -->

51
snippets/not-selector.md Normal file
View File

@ -0,0 +1,51 @@
### :not selector
The `:not` psuedo selector is useful for styling a group of elements, while leaving the last (or specified) element unstyled.
#### HTML
```html
<ul class="css-not-selector-shortcut">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
```
#### CSS
```css
.css-not-selector-shortcut {
display: flex;
}
ul {
padding-left: 0;
}
li {
list-style-type: none;
margin: 0;
padding: 0 0.75rem;
}
li:not(:last-child) {
border-right: 2px solid #d2d5e4;
}
```
#### Demo
#### Explanation
`li:not(:last-child)` specifies that the styles should apply to all `li` elements except
the `:last-child`.
#### Browser support
<span class="snippet__support-note">✅ No caveats.</span>
- https://caniuse.com/#feat=css-sel3
<!-- tags: visual -->

49
snippets/offscreen.md Normal file
View File

@ -0,0 +1,49 @@
### Offscreen
A bulletproof way to completely hide an element visually and positionally in the DOM while still allowing it to be accessed by JavaScript and readable by screen readers. This method is very useful for accessibility ([ADA](https://adata.org/learn-about-ada)) development when more context is needed for visually-impaired users. As an alternative to `display: none` which is not readable by screen readers or `visibility: hidden` which takes up physical space in the DOM.
#### HTML
```html
<a class="button" href="http://pantswebsite.com">
Learn More
<span class="offscreen"> about pants</span>
</a>
```
#### CSS
```css
.offscreen {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
```
#### Demo
#### Explanation
1. Remove all borders.
2. Use `clip` to indicate that no part of the element should be shown.
3. Make the height and width of the element 1px.
4. Negate the elements height and width using `margin: -1px`.
5. Hide the element's overflow.
6. Remove all padding.
7. Position the element absolutely so that it does not take up space in the DOM.
#### Browser support
<span class="snippet__support-note">✅ No caveats.</span>
(Although `clip` technically has been depreciated, the newer `clip-path` currently has very limited browser support.)
- https://caniuse.com/#search=clip
<!-- tags: layout, visual -->

View File

@ -7,7 +7,14 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
```html
<div class="overflow-scroll-gradient">
<div class="overflow-scroll-gradient__scroller">
Content to be scrolled
Lorem ipsum dolor sit amet consectetur adipisicing elit. <br>
Iure id exercitationem nulla qui repellat laborum vitae, <br>
molestias tempora velit natus. Quas, assumenda nisi. <br>
Quisquam enim qui iure, consequatur velit sit? <br>
Lorem ipsum dolor sit amet consectetur adipisicing elit.<br>
Iure id exercitationem nulla qui repellat laborum vitae, <br>
molestias tempora velit natus. Quas, assumenda nisi. <br>
Quisquam enim qui iure, consequatur velit sit?
</div>
</div>
```
@ -35,50 +42,13 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
background: white;
width: 240px;
height: 200px;
padding: 15px 0;
padding: 15px;
line-height: 1.2;
text-align: center;
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__overflow-scroll-gradient">
<div class="snippet-demo__overflow-scroll-gradient__scroller">
Content to be scrolled
</div>
</div>
</div>
<style>
.snippet-demo__overflow-scroll-gradient {
position: relative;
}
.snippet-demo__overflow-scroll-gradient::after {
content: '';
background: linear-gradient(rgba(255, 255, 255, 0.001), white);
position: absolute;
width: 240px;
height: 25px;
bottom: 0;
pointer-events: none;
}
.snippet-demo__overflow-scroll-gradient__scroller {
overflow-y: scroll;
background: white;
width: 240px;
height: 200px;
padding: 15px 0;
line-height: 1.2;
text-align: center;
}
</style>
<script>
document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').innerHTML = 'content '.repeat(100)
</script>
#### Explanation
1. `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.
@ -96,6 +66,6 @@ document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').inne
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-gradients
- https://caniuse.com/#feat=css-gradients
<!-- tags: visual -->

View File

@ -1,11 +1,11 @@
### Popout menu
Reveals an interactive popout menu on hover.
Reveals an interactive popout menu on hover and focus.
#### HTML
```html
<div class="reference">
<div class="reference" tabindex="0">
<div class="popout-menu">
Popout menu
</div>
@ -17,60 +17,36 @@ Reveals an interactive popout menu on hover.
```css
.reference {
position: relative;
background: tomato;
width: 100px;
height: 100px;
}
.popout-menu {
position: absolute;
visibility: hidden;
left: 100%;
background: #333;
color: white;
padding: 15px;
}
.reference:hover > .popout-menu {
.reference:hover > .popout-menu,
.reference:focus > .popout-menu,
.reference:focus-within > .popout-menu {
visibility: visible;
}
```
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__reference">
<div class="snippet-demo__popout-menu">
Popout menu
</div>
</div>
</div>
<style>
.snippet-demo__reference {
background: linear-gradient(135deg, #ff4c9f, #ff7b74);
height: 75px;
width: 75px;
position: relative;
will-change: transform;
}
.snippet-demo__popout-menu {
position: absolute;
visibility: hidden;
left: 100%;
background: #333;
color: white;
font-size: 0.9rem;
padding: 0.4rem 0.8rem;
width: 100px;
text-align: center;
}
.snippet-demo__reference:hover > .snippet-demo__popout-menu {
visibility: visible;
}
</style>
#### Explanation
1. `position: relative` on the reference parent establishes a Cartesian positioning context for its child.
2. `position: absolute` takes the popout menu out of the flow of the document and positions it
in relation to the parent.
2. `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.
3. `left: 100%` moves the the popout menu 100% of its parent's width from the left.
4. `visibility: hidden` hides the popout menu initially and allows for transitions (unlike `display: none`).
5. `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate
children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.
5. `.reference:hover > .popout-menu` means that when `.reference` is hovered over, select immediate children with a class of `.popout-menu` and change their `visibility` to `visible`, which shows the popout.
6. `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.
7. `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.
#### Browser support

View File

@ -1,6 +1,6 @@
### Pretty text underline
A nicer alternative to `text-decoration: underline` where descenders do not clip the underline.
A nicer alternative to `text-decoration: underline` or `<u></u>` where descenders do not clip the underline.
Natively implemented as `text-decoration-skip-ink: auto` but it has less control over the underline.
#### HTML
@ -13,14 +13,12 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
```css
.pretty-text-underline {
font-family: Arial, sans-serif;
display: inline;
font-size: 18px;
text-shadow: 1px 1px 0 #f5f6f9, -1px 1px 0 #f5f6f9, -1px -1px 0 #f5f6f9, 1px -1px 0 #f5f6f9;
text-shadow: 1px 1px #f5f6f9, -1px 1px #f5f6f9, -1px -1px #f5f6f9, 1px -1px #f5f6f9;
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
background-position: 0 0.98em;
background-repeat: repeat-x;
background-size: 1px 1px;
background-position: bottom;
background-repeat: no-repeat;
background-size: 100% 1px;
}
.pretty-text-underline::-moz-selection {
background-color: rgba(0, 150, 255, 0.3);
@ -34,52 +32,25 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__pretty-text-underline">Pretty text underline without clipping descending letters.</p>
</div>
<style>
.snippet-demo__pretty-text-underline {
font-family: Arial, sans-serif;
display: inline;
font-size: 18px !important;
text-shadow: 1px 1px 0 #f5f6f9,
-1px 1px 0 #f5f6f9,
-1px -1px 0 #f5f6f9,
1px -1px 0 #f5f6f9;
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
background-position: 0 0.98em;
background-repeat: repeat-x;
background-size: 1px 1px;
}
.snippet-demo__pretty-text-underline::-moz-selection {
background-color: rgba(0, 150, 255, 0.3);
text-shadow: none;
}
.snippet-demo__pretty-text-underline::selection {
background-color: rgba(0, 150, 255, 0.3);
text-shadow: none;
}
</style>
#### Explanation
1. `text-shadow: ...` has 4 values with offsets that cover a 4x4 px area to ensure the underline
1. `text-shadow` uses 4 values with offsets that cover a 4x4 px area to ensure the underline
has a "thick" shadow that covers the line where descenders clip it. Use a color
that matches the background. For a larger font, use a larger `px` size.
2. `background-image: linear-gradient(...)` creates a 90deg gradient with the current
that matches the background. For a larger font, use a larger `px` size. Additional values
can create an even thicker shadow, and subpixel values can also be used.
2. `background-image: linear-gradient(...)` creates a 90deg gradient using the
text color (`currentColor`).
3. The `background-*` properties size the gradient as 1x1px at the bottom and repeats it along the x-axis.
4. The `::selection` pseudo selector ensures the text shadow does not interfere with text
3. The `background-*` properties size the gradient as 100% of the width of the block and 1px
in height at the bottom and disables repetition, which creates a 1px underline beneath
the text.
4. The `::selection` pseudo selector rule ensures the text shadow does not interfere with text
selection.
#### Browser support
<span class="snippet__support-note">⚠️ The distance of the underline from the text depends on the internal metrics of a font, so you must ensure everyone sees the same font (i.e. no system fonts which will change based on the OS).</span>
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-textshadow
* https://caniuse.com/#feat=css-gradients
- https://caniuse.com/#feat=css-textshadow
- https://caniuse.com/#feat=css-gradients
<!-- tags: visual -->

View File

@ -6,7 +6,7 @@ Resets all styles to default values with one property. This will not affect `dir
```html
<div class="reset-all-styles">
<h4>Title</h4>
<h5>Title</h5>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?</p>
</div>
```
@ -21,19 +21,6 @@ Resets all styles to default values with one property. This will not affect `dir
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__reset-all-styles">
<h3>Title</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?</p>
</div>
</div>
<style>
.snippet-demo__reset-all-styles {
all: initial;
}
</style>
#### Explanation
The `all` property allows you to reset all styles (inherited or not) to default values.
@ -42,6 +29,6 @@ The `all` property allows you to reset all styles (inherited or not) to default
<span class="snippet__support-note">⚠️ MS Edge status is under consideration.</span>
* https://caniuse.com/#feat=css-all
- https://caniuse.com/#feat=css-all
<!-- tags: visual -->

View File

@ -18,52 +18,30 @@ Uses an SVG shape to separate two different blocks to create more a interesting
}
.shape-separator::after {
content: '';
background-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxLjQxNCI+PHBhdGggZD0iTTEyIDEybDEyIDEySDBsMTItMTJ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+);
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12'%3E%3Cpath d='m12 0l12 12h-24z' fill='%23fff'/%3E%3C/svg%3E");
position: absolute;
width: 100%;
height: 24px;
height: 12px;
bottom: 0;
}
```
#### Demo
<div class="snippet-demo is-distinct">
<div class="snippet-demo__shape-separator"></div>
</div>
<style>
.snippet-demo__shape-separator {
position: relative;
height: 48px;
margin: -0.75rem -1.25rem;
}
.snippet-demo__shape-separator::after {
content: '';
background-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxLjQxNCI+PHBhdGggZD0iTTEyIDEybDEyIDEySDBsMTItMTJ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+);
position: absolute;
width: 100%;
height: 24px;
bottom: 0;
}
</style>
#### Explanation
1. `position: relative` on the element establishes a Cartesian positioning context for pseudo elements.
2. `::after` defines a pseudo element.
3. `background-image: url(...)` adds the SVG shape (a 24x24 triangle in base64 format) as the background image
of the pseudo element, which repeats by default. It must be the same color as the block that is being
separated.
3. `background-image: url(...)` adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use [the URL-encoder for SVG](http://yoksel.github.io/url-encoder/).
4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
5. `width: 100%` ensures the element stretches the entire width of its parent.
6. `height: 24px` is the same height as the shape.
6. `height: 12px` is the same height as the shape.
7. `bottom: 0` positions the pseudo element at the bottom of the parent.
#### Browser support
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=svg
- https://caniuse.com/#feat=svg
<!-- tags: visual -->

View File

@ -30,34 +30,6 @@ span {
#### Demo
<div class="snippet-demo">
<nav class="snippet-demo__sibling-fade">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
<span>Item 4</span>
<span>Item 5</span>
<span>Item 6</span>
</nav>
</div>
<style>
.snippet-demo__sibling-fade {
cursor: default;
line-height: 2;
vertical-align: middle;
}
.snippet-demo__sibling-fade span {
padding: 1rem;
transition: opacity 0.2s;
}
.snippet-demo__sibling-fade:hover span:not(:hover) {
opacity: 0.5;
}
</style>
#### Explanation
1. `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.2 seconds.
@ -68,7 +40,7 @@ span {
<span class="snippet__support-note">✅ No caveats.</span>
* https://caniuse.com/#feat=css-sel3
* https://caniuse.com/#feat=css-transitions
- https://caniuse.com/#feat=css-sel3
- https://caniuse.com/#feat=css-transitions
<!-- tags: interactivity -->

View File

@ -19,16 +19,6 @@ Uses the native font of the operating system to get close to a native app feel.
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__system-font-stack">This text uses the system font.</p>
</div>
<style>
.snippet-demo__system-font-stack {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
</style>
#### Explanation
The browser looks for each successive font, preferring the first one if possible, and

72
snippets/toggle-switch.md Normal file
View File

@ -0,0 +1,72 @@
### Toggle switch
Creates a toggle switch with CSS only.
#### HTML
```html
<input type="checkbox" id="toggle" class="offscreen" />
<label for="toggle" class="switch"></label>
```
#### CSS
```css
.switch {
position: relative;
display: inline-block;
width: 40px;
height: 20px;
background-color: rgba(0, 0, 0, 0.25);
border-radius: 20px;
transition: all 0.3s;
}
.switch::after {
content: '';
position: absolute;
width: 18px;
height: 18px;
border-radius: 18px;
background-color: white;
top: 1px;
left: 1px;
transition: all 0.3s;
}
input[type='checkbox']:checked + .switch::after {
transform: translateX(20px);
}
input[type='checkbox']:checked + .switch {
background-color: #7983ff;
}
.offscreen {
position: absolute;
left: -9999px;
}
```
#### Demo
#### Explanation
This effect is styling only the `<label>` element to look like a toggle switch, and hiding the actual `<input>` checkbox by positioning it offscreen. When clicking the label associated with the `<input>` element, it sets the `<input>` checkbox into the `:checked` state.
1. The `for` attribute associates the `<label>` with the appropriate `<input>` checkbox element by its `id`.
2. `.switch::after` defines a pseudo-element for the `<label>` to create the circular knob.
3. `input[type='checkbox']:checked + .switch::after` targets the `<label>`'s pseudo-element's style when the checkbox is `checked`.
4. `transform: translateX(20px)` moves the pseudo-element (knob) 20px to the right when the checkbox is `checked`.
5. `background-color: #7983ff;` sets the background-color of the switch to a different color when the checkbox is `checked`.
6. `.offscreen` moves the `<input>` checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.
7. `transition: all 0.3s` specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the `<label>`'s `background-color` and the pseudo-element's `transform` property when the checkbox is checked.
#### Browser support
<span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
- https://caniuse.com/#feat=transforms2d
<!-- tags: visual, interactivity -->
<!-- date: 2018-10-03 -->

View File

@ -0,0 +1,48 @@
### Transform centering
Vertically and horizontally centers a child element within its parent element using `position: absolute` and `transform: translate()` (as an alternative to `flexbox` or `display: table`). Similar to `flexbox`, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.
#### HTML
```html
<div class="parent">
<div class="child">Centered content</div>
</div>
```
#### CSS
```css
.parent {
border: 1px solid #333;
height: 250px;
position: relative;
width: 250px;
}
.child {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
```
#### Demo
#### Explanation
1. `position: absolute` on the child element allows it to be positioned based on its containing block.
2. `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.
3. `transform: translate(-50%, -50%)` allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
Note: Fixed height and width on parent element is for the demo only.
#### Browser support
<span class="snippet__support-note">⚠️ Requires prefix for full support.</span>
- https://caniuse.com/#search=transform
<!-- tags: layout -->

View File

@ -22,60 +22,6 @@ Creates a triangle shape with pure CSS.
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__triangles">
<div class="snippet-demo__triangle snippet-demo__triangle-1"></div>
<div class="snippet-demo__triangle snippet-demo__triangle-2"></div>
<div class="snippet-demo__triangle snippet-demo__triangle-3"></div>
<div class="snippet-demo__triangle snippet-demo__triangle-4"></div>
<div class="snippet-demo__triangle snippet-demo__triangle-5"></div>
</div>
</div>
<style>
.snippet-demo__triangles {
display: flex;
align-items: center;
}
.snippet-demo__triangle {
display: inline-block;
width: 0;
height: 0;
margin-right: 0.25rem;
}
.snippet-demo__triangle-1 {
border-top: 20px solid #333;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
}
.snippet-demo__triangle-2 {
border-bottom: 20px solid #333;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
}
.snippet-demo__triangle-3 {
border-left: 20px solid #333;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
.snippet-demo__triangle-4 {
border-right: 20px solid #333;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
.snippet-demo__triangle-5 {
border-top: 40px solid #333;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}
</style>
#### Explanation
[View this link for a detailed explanation.](https://stackoverflow.com/q/7073484)

View File

@ -21,22 +21,6 @@ If the text is longer than one line, it will be truncated and end with an ellips
#### Demo
<div class="snippet-demo">
<p class="snippet-demo__truncate-text">
This text will be truncated if it exceeds 200px in width.
</p>
</div>
<style>
.snippet-demo__truncate-text {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 200px;
margin: 0;
}
</style>
#### Explanation
1. `overflow: hidden` prevents the text from overflowing its dimensions
@ -50,6 +34,6 @@ If the text is longer than one line, it will be truncated and end with an ellips
<span class="snippet__support-note">⚠️ Only works for single line elements.</span>
* https://caniuse.com/#feat=text-overflow
- https://caniuse.com/#feat=text-overflow
<!-- tags: layout -->

View File

@ -12,7 +12,7 @@ html {
body {
font-family: -apple-system, BlinkMacSystemFont, Roboto, Segoe UI, 'Helvetica Neue', Helvetica,
Arial, sans-serif;
background: #f6f7fd;
background: #f2f3f8;
color: rgb(50, 75, 100);
line-height: 1.5;
}
@ -62,6 +62,12 @@ ol {
@media (min-width: 992px) {
.content-wrapper {
margin-left: 200px;
margin-left: 20%;
}
}
@media (min-width: 1400px) {
.content-wrapper {
margin-left: 275px;
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
.sidebar {
background: #202e4e;
background: #273149;
position: fixed;
z-index: 2;
width: 100%;
@ -23,7 +23,7 @@
}
&__links {
background: #202e4e;
background: #273149;
overflow-y: auto;
transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
transform-origin: 0% 0%;
@ -47,10 +47,11 @@
&__link {
display: block;
color: #e3f5ff;
padding: 0.5rem 0.75rem;
padding: 0.75rem;
padding-right: 1.5rem;
margin-right: -0.75rem;
transition: all 0.1s ease-out;
border-left: 2px solid #576a85;
margin: 0.5rem;
font-weight: 500;
font-size: 0.95rem;
@ -70,6 +71,12 @@
color: #e3f5ff;
margin-bottom: 0.5rem;
}
&__new {
width: 1.25rem;
vertical-align: middle;
margin-right: 0.25rem;
}
}
@media (min-width: 992px) {
@ -77,26 +84,15 @@
left: 0;
top: 0;
bottom: 0;
width: 15%;
max-width: 250px;
min-width: 200px;
width: 20%;
height: 100%;
background: linear-gradient(-30deg, #2a3d67, #14264e);
background: linear-gradient(-30deg, #273149, #1c273f);
box-shadow: 0.4rem 0.4rem 0.8rem rgba(0, 32, 64, 0.1);
overflow-y: auto;
color: white;
&::-webkit-scrollbar-track {
background-color: rgba(0, 0, 0, 0.6);
}
&::-webkit-scrollbar {
width: 10px;
background-color: #4b6191;
}
&::-webkit-scrollbar-thumb {
background-color: #4b6191;
@media (min-width: 1400px) {
width: 275px;
}
&__links {
@ -114,3 +110,20 @@
}
}
}
html:not(.macOS) {
.sidebar {
&::-webkit-scrollbar-track {
background-color: rgba(0, 0, 0, 0.6);
}
&::-webkit-scrollbar {
width: 10px;
background-color: #505b76;
}
&::-webkit-scrollbar-thumb {
background-color: #505b76;
}
}
}

View File

@ -59,22 +59,23 @@
border-bottom-color: darken(#c6d6ea, 5);
background: white;
box-shadow: 0 0.25rem 0.5rem -0.1rem rgba(0, 32, 64, 0.15);
background-repeat: no-repeat;
}
&[data-type='HTML'] {
color: white;
border: none;
background: linear-gradient(135deg, #ff4c9f, #ff7b74);
background-image: linear-gradient(135deg, #ff4c9f, #ff7b74);
}
&[data-type='CSS'] {
color: white;
border: none;
background: linear-gradient(135deg, #7983ff, #5f9de9);
background-image: linear-gradient(135deg, #7983ff, #5f9de9);
}
&[data-type='JavaScript'] {
color: white;
border: none;
background: linear-gradient(135deg, #ffb000, #f58818);
background-image: linear-gradient(135deg, #ffb000, #f58818);
}
}
@ -118,6 +119,14 @@
&__tag {
}
&__new {
position: absolute;
top: -1rem;
left: 50%;
transform: translateX(-50%);
width: 3rem;
}
}
.snippet-demo {

View File

@ -5,6 +5,7 @@
justify-content: center;
flex-wrap: wrap;
margin-bottom: 1rem;
padding: 0 1rem;
&__tag {
display: inline-block;
@ -20,7 +21,7 @@
vertical-align: middle;
line-height: 2;
padding: 0 0.5rem;
margin-right: 0.5rem;
margin: 0 0.1rem;
transition: all 0.1s ease-out;
outline: 0;

View File

@ -1,8 +1,9 @@
code[class*='language-'],
pre[class*='language-'] {
color: rgb(50, 75, 100);
color: rgb(215, 236, 255);
background: none;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-family: 'Operator Mono', 'Roboto Mono', Menlo, Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono',
monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
@ -59,7 +60,7 @@ pre.is-option {
:not(pre) > code[class*='language-'],
pre[class*='language-'] {
background: #f5f6f9;
background: linear-gradient(-30deg, #273149, #1c273f);
border-radius: 0.25rem;
}
@ -79,11 +80,11 @@ pre[class*='language-'] {
.token.selector,
.token.attr-name {
color: #da7800;
color: #c7f683;
}
.token.punctuation {
color: #93a0c7;
color: #5ac8e3;
}
.namespace {
@ -91,7 +92,7 @@ pre[class*='language-'] {
}
.token.tag {
color: #e22f70;
color: #2cefd8;
}
.token.property,
@ -100,7 +101,7 @@ pre[class*='language-'] {
.token.constant,
.token.symbol,
.token.deleted {
color: #0087ca;
color: #85b4ff;
}
.token.string,
@ -110,23 +111,23 @@ pre[class*='language-'] {
.token.char,
.token.builtin,
.token.inserted {
color: #008a7e;
color: #ffd694;
}
.token.operator,
.token.entity,
.style .token.string {
color: #f53737;
color: #ff9bbe;
}
.token.important,
.token.atrule,
.token.keyword {
color: #7552ff;
color: #b7adff;
}
.token.function {
color: #396dff;
color: #25d0e5;
}
.token.regex,

View File

@ -1,10 +1,17 @@
<header class="header">
<div class="container">
<img class="header__leaves" draggable="false" id="header__leaves1" src="./src/img/leaves.svg" alt>
<img class="header__leaves" draggable="false" id="header__leaves2" src="./src/img/leaves.svg" alt>
<img id="header__blob" draggable="false" src="./src/img/blob.png" alt>
<div class="header__content">
<img class="header__logo" draggable="false" src="./src/img/logo.png">
<h1 class="header__heading">30 Seconds of <strong class="header__css">CSS</strong></h1>
<p class="header__description">
A curated collection of useful CSS snippets you can understand in 30 seconds or less.
</p>
<a class="github-button header__github-button" href="https://github.com/atomiks/30-seconds-of-css" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star atomiks/30-seconds-of-css on GitHub">Star</a>
<div class="header__github-button-wrapper">
<a class="github-button header__github-button" href="https://github.com/30-seconds/30-seconds-of-css" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star 30-seconds/30-seconds-of-css on GitHub">Star</a>
</div>
</div>
</div>
</header>

BIN
src/img/blob.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

1
src/img/leaves.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 14 KiB

1
src/img/new.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -1,4 +1,4 @@
import jump from '../deps/jump'
import jump from 'jump.js'
import { select, scrollY, easeOutQuint } from '../deps/utils'
const backToTopButton = select('.back-to-top-button')

View File

@ -1,4 +1,4 @@
import jump from '../deps/jump'
import jump from 'jump.js'
import { select, selectAll, easeOutQuint } from '../deps/utils'
const menu = select('.hamburger')

View File

@ -1,196 +0,0 @@
;(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory())
: typeof define === 'function' && define.amd ? define(factory) : (global.Jump = factory())
})(this, function() {
'use strict'
// Robert Penner's easeInOutQuad
// find the rest of his easing functions here: http://robertpenner.com/easing/
// find them exported for ES6 consumption here: https://github.com/jaxgeller/ez.js
var easeInOutQuad = function easeInOutQuad(t, b, c, d) {
t /= d / 2
if (t < 1) return c / 2 * t * t + b
t--
return -c / 2 * (t * (t - 2) - 1) + b
}
var _typeof =
typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
? function(obj) {
return typeof obj
}
: function(obj) {
return obj &&
typeof Symbol === 'function' &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? 'symbol'
: typeof obj
}
var jumper = function jumper() {
// private variable cache
// no variables are created during a jump, preventing memory leaks
var element = void 0 // element to scroll to (node)
var start = void 0 // where scroll starts (px)
var stop = void 0 // where scroll stops (px)
var offset = void 0 // adjustment from the stop position (px)
var easing = void 0 // easing function (function)
var a11y = void 0 // accessibility support flag (boolean)
var distance = void 0 // distance of scroll (px)
var duration = void 0 // scroll duration (ms)
var timeStart = void 0 // time scroll started (ms)
var timeElapsed = void 0 // time spent scrolling thus far (ms)
var next = void 0 // next scroll position (px)
var callback = void 0 // to call when done scrolling (function)
// scroll position helper
function location() {
return window.scrollY || window.pageYOffset
}
// element offset helper
function top(element) {
return element.getBoundingClientRect().top + start
}
// rAF loop helper
function loop(timeCurrent) {
// store time scroll started, if not started already
if (!timeStart) {
timeStart = timeCurrent
}
// determine time spent scrolling so far
timeElapsed = timeCurrent - timeStart
// calculate next scroll position
next = easing(timeElapsed, start, distance, duration)
// scroll to it
window.scrollTo(0, next)
// check progress
timeElapsed < duration
? window.requestAnimationFrame(loop) // continue scroll loop
: done() // scrolling is done
}
// scroll finished helper
function done() {
// account for rAF time rounding inaccuracies
window.scrollTo(0, start + distance)
// if scrolling to an element, and accessibility is enabled
if (element && a11y) {
// add tabindex indicating programmatic focus
element.setAttribute('tabindex', '-1')
// focus the element
element.focus()
}
// if it exists, fire the callback
if (typeof callback === 'function') {
callback()
}
// reset time for next jump
timeStart = false
}
// API
function jump(target) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
// resolve options, or use defaults
duration = options.duration || 1000
offset = options.offset || 0
callback = options.callback // "undefined" is a suitable default, and won't be called
easing = options.easing || easeInOutQuad
a11y = options.a11y || false
// cache starting position
start = location()
// resolve target
switch (typeof target === 'undefined' ? 'undefined' : _typeof(target)) {
// scroll from current position
case 'number':
element = undefined // no element to scroll to
a11y = false // make sure accessibility is off
stop = start + target
break
// scroll to element (node)
// bounding rect is relative to the viewport
case 'object':
element = target
stop = top(element)
break
// scroll to element (selector)
// bounding rect is relative to the viewport
case 'string':
element = document.querySelector(target)
stop = top(element)
break
}
// resolve scroll distance, accounting for offset
distance = stop - start + offset
// resolve duration
switch (_typeof(options.duration)) {
// number in ms
case 'number':
duration = options.duration
break
// function passed the distance of the scroll
case 'function':
duration = options.duration(distance)
break
}
// start the loop
window.requestAnimationFrame(loop)
}
// expose only the jump method
return jump
}
// export singleton
var singleton = jumper()
return (() => {
let scrolling
const end = () => (scrolling = false)
return (to, options = {}) => {
if (scrolling) return
const scrollY = window.scrollY || window.pageYOffset
if (to !== '.header') location.hash = to
scroll(0, scrollY)
scrolling = true
setTimeout(end, options.duration || 0)
return singleton(to, options)
}
})()
})

View File

@ -36,6 +36,10 @@ if (/iPhone|iPad|iPod/.test(navigator.platform) && !window.MSStream) {
document.body.style.cursor = 'pointer'
}
if (/Mac/.test(navigator.platform)) {
document.documentElement.classList.add('macOS')
}
/*
* A small utility to fix the letter kerning on macOS Chrome and Firefox when using the system font
* (San Francisco). It is now fixed in the text rendering engine in FF 58 and Chrome 64.

View File

@ -18,3 +18,6 @@ exports.createElement = str => {
el.innerHTML = str
return el.firstElementChild
}
exports.getCode = (type, str) =>
(str.match(new RegExp('```' + type + '([\\s\\S]*?)```')) || [])[1] || ''