fix typo in system-font-stack.md
This commit is contained in:
BIN
dist/410f94d6c61e5beb62212a28c82ecef3.png
vendored
Normal file
BIN
dist/410f94d6c61e5beb62212a28c82ecef3.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
999
dist/6f87738ba5ca74ac9104fc97c6eee446.html
vendored
Normal file
999
dist/6f87738ba5ca74ac9104fc97c6eee446.html
vendored
Normal file
@ -0,0 +1,999 @@
|
|||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<title>30 Seconds of CSS</title>
|
||||||
|
<link rel="icon" type="image/png" sizes="32x32" href="/dist/410f94d6c61e5beb62212a28c82ecef3.png">
|
||||||
|
<script src="/dist/719042b6d7879d0a403a9eaac2211738.js" defer=""></script>
|
||||||
|
<script async="" defer="" src="https://buttons.github.io/buttons.js"></script>
|
||||||
|
<link rel="stylesheet" href="/dist/719042b6d7879d0a403a9eaac2211738.css"></head>
|
||||||
|
<body>
|
||||||
|
<button class="back-to-top-button">↑</button>
|
||||||
|
<aside class="sidebar">
|
||||||
|
<button class="hamburger hamburger--spin sidebar__menu" type="button">
|
||||||
|
<span class="hamburger-box">
|
||||||
|
<span class="hamburger-inner"></span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
<div class="sidebar__links">
|
||||||
|
<a class="sidebar__link" href="#clearfix">Clearfix</a>
|
||||||
|
<a class="sidebar__link" href="#custom-text-selection">Custom text selection</a>
|
||||||
|
<a class="sidebar__link" href="#easing-variables">Easing variables</a>
|
||||||
|
<a class="sidebar__link" href="#etched-text">Etched text</a>
|
||||||
|
<a class="sidebar__link" href="#gradient-text">Gradient text</a>
|
||||||
|
<a class="sidebar__link" href="#hairline-border">Hairline border</a>
|
||||||
|
<a class="sidebar__link" href="#horizontal-and-vertical-centering">Horizontal and vertical centering</a>
|
||||||
|
<a class="sidebar__link" href="#mouse-cursor-gradient-tracking">Mouse cursor gradient tracking</a>
|
||||||
|
<a class="sidebar__link" href="#overflow-scroll-gradient">Overflow scroll gradient</a>
|
||||||
|
<a class="sidebar__link" href="#popout-menu">Popout menu</a>
|
||||||
|
<a class="sidebar__link" href="#pretty-text-underline">Pretty text underline</a>
|
||||||
|
<a class="sidebar__link" href="#shape-separator">Shape separator</a>
|
||||||
|
<a class="sidebar__link" href="#system-font-stack">System font stack</a>
|
||||||
|
<a class="sidebar__link" href="#triangle">Triangle</a>
|
||||||
|
<a class="sidebar__link" href="#truncate-text">Truncate text</a>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
<div class="content-wrapper">
|
||||||
|
<header class="header">
|
||||||
|
<div class="container">
|
||||||
|
<img class="header__logo" draggable="false" src="/dist/ac46b6c579212c73b4f2afaa428f354c.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>
|
||||||
|
|
||||||
|
<!-- Place this tag where you want the button to render. -->
|
||||||
|
<a class="github-button header__github-button" href="https://github.com/atomiks/30-seconds-of-css" data-icon="octicon-star" data-size="large" aria-label="Star atomiks/30-seconds-of-css on GitHub">Star</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main class="main">
|
||||||
|
<div class="container">
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="clearfix">Clearfix</h3>
|
||||||
|
<p>Ensures that an element self-clears its children.</p>
|
||||||
|
<h6 data-type="Note: This is useful only if you are still using float to build layouts. Please consider to use a modern approach with flexbox layout or grid layout.">Note: This is useful only if you are still using float to build layouts. Please consider to use a modern approach with flexbox layout or grid layout.</h6>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="clearfix">
|
||||||
|
<div class="floated">float a</div>
|
||||||
|
<div class="floated">float b</div>
|
||||||
|
<div class="floated">float c</div>
|
||||||
|
</div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.clearfix::after {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
.floated {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>.clearfix::after</code> defines a pseudo element.</li>
|
||||||
|
<li><code>content: ''</code> allows the pseudo element to affect layout.</li>
|
||||||
|
<li><code>clear: both</code> indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
99+%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="custom-text-selection">Custom text selection</h3>
|
||||||
|
<p>Changes the styling of text selection.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="custom-text-selection">Select some of this text.</p>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.custom-text-selection::selection {
|
||||||
|
background: red;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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: red;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.snippet-demo__custom-text-selection::-moz-selection {
|
||||||
|
background: red;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<p><code>::selection</code> defines a pseudo selector on an element to style text within it when selected.</p>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
84.6%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">⚠️ Requires prefixes for full support and is not actually
|
||||||
|
in any specification.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-selection" target="_blank">https://caniuse.com/#feat=css-selection</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="easing-variables">Easing variables</h3>
|
||||||
|
<p>Variables that can be reused for <code>transition-timing-function</code> properties, more powerful than the built-in <code>ease</code>, <code>ease-in</code>, <code>ease-out</code> and <code>ease-in-out</code>.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="easing-variables"></div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">: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);
|
||||||
|
}
|
||||||
|
.easing-variables {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
background: #333;
|
||||||
|
transition: transform 1s var(--ease-out-quart);
|
||||||
|
}
|
||||||
|
.easing-variables:hover {
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<p>The variables are defined globally with the <code>:root</code> CSS pseudo-class, which matches the root element of a tree representing the document. In HTML, <code>:root</code> represents the <code><html></code> element and is identical
|
||||||
|
to the selector html, except that its specificity is higher.</p>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
87.2%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-variables" target="_blank">https://caniuse.com/#feat=css-variables</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="etched-text">Etched text</h3>
|
||||||
|
<p>Creates an effect where text appears to be "etched" or engraved into the background.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="etched-text">I appear etched into the background.</p>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.etched-text {
|
||||||
|
text-shadow: 0 2px white;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #b8bec5;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<p><code>text-shadow: 0 2px white</code> creates a white shadow offset <code>0px</code> horizontally and <code>2px</code> vertically from the origin position.</p>
|
||||||
|
<p>The background must be darker than the shadow for the effect to work.</p>
|
||||||
|
<p>The text color should be slightly faded to make it look like it's engraved/carved out of the background.</p>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
97.9%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-textshadow" target="_blank">https://caniuse.com/#feat=css-textshadow</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="gradient-text">Gradient text</h3>
|
||||||
|
<p>Gives text a gradient color.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="gradient-text">Gradient text</p>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.gradient-text {
|
||||||
|
background: -webkit-linear-gradient(pink, red);
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>background: -webkit-linear-gradient(...)</code> gives the text element a gradient background.</li>
|
||||||
|
<li><code>webkit-text-fill-color: transparent</code> fills the text with a transparent color.</li>
|
||||||
|
<li><code>webkit-background-clip: text</code> clips the background with the text, filling the text with the gradient background as the color.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
90.7%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">⚠️ Uses non-standard properties.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=text-stroke" target="_blank">https://caniuse.com/#feat=text-stroke</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="hairline-border">Hairline border</h3>
|
||||||
|
<p>Gives an element a border equal to 1 native device pixel in width, which can look very sharp and crisp.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="hairline-border">text</div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.hairline-border {
|
||||||
|
box-shadow: 0 0 0 1px;
|
||||||
|
}
|
||||||
|
@media (min-resolution: 2dppx) {
|
||||||
|
.hairline-border {
|
||||||
|
box-shadow: 0 0 0 0.5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (min-resolution: 3dppx) {
|
||||||
|
.hairline-border {
|
||||||
|
box-shadow: 0 0 0 0.33333333px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (min-resolution: 4dppx) {
|
||||||
|
.hairline-border {
|
||||||
|
box-shadow: 0 0 0 0.25px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>box-shadow</code>, when only using spread, adds a psuedo-border which can use subpixels*.</li>
|
||||||
|
<li>Use <code>@media (min-resolution: ...)</code> to check the device pixel ratio (<code>1ddpx</code> equals 96 DPI), setting the spread of the <code>box-shadow</code> equal to <code>1 / dppx</code>.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser Support">Browser Support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
95.0%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">⚠️ Needs alternate syntax and JavaScript user agent checking for full support.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-boxshadow" target="_blank">https://caniuse.com/#feat=css-boxshadow</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-media-resolution" target="_blank">https://caniuse.com/#feat=css-media-resolution</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<hr>
|
||||||
|
<p>*Chrome does not support subpixel values on <code>border</code>. Safari does not support subpixel values on <code>box-shadow</code>. Firefox supports subpixel values on both.</p>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="horizontal-and-vertical-centering">Horizontal and vertical centering</h3>
|
||||||
|
<p>Horizontally and vertically centers a child element within a parent element.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="horizontal-and-vertical-centering">
|
||||||
|
<div class="child"></div>
|
||||||
|
</div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.horizontal-and-vertical-centering {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<div class="snippet-demo">
|
||||||
|
<div class="snippet-demo__horizontal-and-vertical-centering">
|
||||||
|
<p class="snippet-demo__horizontal-and-vertical-centering__child">Centered content.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<style>
|
||||||
|
.snippet-demo__horizontal-and-vertical-centering {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>display: flex</code> enables flexbox.</li>
|
||||||
|
<li><code>justify-content: center</code> centers the child horizontally.</li>
|
||||||
|
<li><code>align-items: center</code> centers the child vertically.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
97.8%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">⚠️ Needs prefixes for full support.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=flexbox" target="_blank">https://caniuse.com/#feat=flexbox</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="mouse-cursor-gradient-tracking">Mouse cursor gradient tracking</h3>
|
||||||
|
<p>A hover effect where the gradient follows the mouse cursor.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><button class="mouse-cursor-gradient-tracking">
|
||||||
|
<span>Hover me</span>
|
||||||
|
</button>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.mouse-cursor-gradient-tracking {
|
||||||
|
position: relative;
|
||||||
|
background: #2379f7;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.mouse-cursor-gradient-tracking span {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.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, pink, transparent);
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
transition: width .2s ease, height .2s ease;
|
||||||
|
}
|
||||||
|
.mouse-cursor-gradient-tracking:hover::before {
|
||||||
|
--size: 200px;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="JavaScript">JavaScript</h4><pre><code class="lang-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
|
||||||
|
btn.style.setProperty('--x', x + 'px')
|
||||||
|
btn.style.setProperty('--y', y + 'px')
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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: #2379f7;
|
||||||
|
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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<p><em>TODO</em></p>
|
||||||
|
<p><strong>Note!</strong></p>
|
||||||
|
<p>If the element's parent has a positioning context (<code>position: relative</code>), you will need to subtract its offsets as well.</p>
|
||||||
|
<pre><code class="lang-js">var x = e.pageX - btn.offsetLeft - btn.offsetParent.offsetLeft
|
||||||
|
var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
87.2%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
<div class="snippet__requires-javascript">Requires JavaScript</div>
|
||||||
|
<span class="snippet__support-note">⚠️ Requires JavaScript.</span>
|
||||||
|
<p></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-variables" target="_blank">https://caniuse.com/#feat=css-variables</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="overflow-scroll-gradient">Overflow scroll gradient</h3>
|
||||||
|
<p>Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="overflow-scroll-gradient">
|
||||||
|
<div class="overflow-scroll-gradient__scroller">
|
||||||
|
Content to be scrolled
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.overflow-scroll-gradient {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.overflow-scroll-gradient::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
width: 300px;
|
||||||
|
height: 25px;
|
||||||
|
background: linear-gradient(rgba(255, 255, 255, 0.001), white); /* transparent keyword is broken in Safari */
|
||||||
|
}
|
||||||
|
.overflow-scroll-gradient__scroller {
|
||||||
|
overflow-y: scroll;
|
||||||
|
background: white;
|
||||||
|
width: 300px;
|
||||||
|
height: 250px;
|
||||||
|
padding: 15px 0;
|
||||||
|
line-height: 1.2;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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: 300px;
|
||||||
|
height: 25px;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
.snippet-demo__overflow-scroll-gradient__scroller {
|
||||||
|
overflow-y: scroll;
|
||||||
|
background: white;
|
||||||
|
width: 300px;
|
||||||
|
height: 250px;
|
||||||
|
padding: 15px 0;
|
||||||
|
line-height: 1.2;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').innerHTML = 'content '.repeat(200)
|
||||||
|
</script>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>position: relative</code> on the parent establishes a Cartesian positioning context for psuedo elements.</li>
|
||||||
|
<li><code>::after</code> defines a pseudo element.</li>
|
||||||
|
<li><code>background-image: linear-gradient(...)</code> adds a linear gradient that fades from transparent to white (top to bottom).</li>
|
||||||
|
<li><code>position: absolute</code> takes the pseudo element out of the flow of the document and positions it in relation to the parent.</li>
|
||||||
|
<li><code>width: 300px</code> matches the size of the scrolling element (which is a child of the parent that has the pseudo element).</li>
|
||||||
|
<li><code>height: 25px</code> is the height of the fading gradient psuedo element, which should be kept relatively small.</li>
|
||||||
|
<li><code>bottom: 0</code> positions the pseudo element at the bottom of the parent.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
94.8%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-gradients" target="_blank">https://caniuse.com/#feat=css-gradients</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="popout-menu">Popout menu</h3>
|
||||||
|
<p>Reveals an interactive popout menu on hover.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="reference">
|
||||||
|
<div class="popout-menu">
|
||||||
|
Popout menu
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.reference {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.popout-menu {
|
||||||
|
position: absolute;
|
||||||
|
visibility: hidden;
|
||||||
|
left: 100%;
|
||||||
|
}
|
||||||
|
.reference:hover > .popout-menu {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>position: relative</code> on the reference parent establishes a Cartesian positioning context for its child.</li>
|
||||||
|
<li><code>position: absolute</code> takes the popout menu out of the flow of the document and positions it in relation to the parent.</li>
|
||||||
|
<li><code>left: 100%</code> moves the the popout menu 100% of its parent's width from the left.</li>
|
||||||
|
<li><code>visibility: hidden</code> hides the popout menu initially and allows for transitions (unlike <code>display: none</code>).</li>
|
||||||
|
<li><code>.reference:hover > .popout-menu</code> means that when <code>.reference</code> is hovered over, select immediate children with a class of <code>.popout-menu</code> and change their <code>visibility</code> to <code>visible</code>,
|
||||||
|
which shows the popout.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
99+%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="pretty-text-underline">Pretty text underline</h3>
|
||||||
|
<p>A nicer alternative to <code>text-decoration: underline</code> where descenders do not clip the underline. Natively implemented as <code>text-decoration-skip-ink: auto</code> but it has less control over the underline.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="pretty-text-underline">Pretty text underline without clipping descending letters.</p>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.pretty-text-underline {
|
||||||
|
display: inline;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
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 1.04em;
|
||||||
|
background-repeat: repeat-x;
|
||||||
|
background-size: 1px 1px;
|
||||||
|
}
|
||||||
|
.pretty-text-underline::selection {
|
||||||
|
background-color: rgba(0, 150, 255, 0.3);
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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 {
|
||||||
|
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 1.04em;
|
||||||
|
background-repeat: repeat-x;
|
||||||
|
background-size: 1px 1px;
|
||||||
|
}
|
||||||
|
.snippet-demo__pretty-text-underline::selection {
|
||||||
|
background-color: rgba(0, 150, 255, 0.3);
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>text-shadow: ...</code> has 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 <code>px</code> size.</li>
|
||||||
|
<li><code>background-image: linear-gradient(...)</code> creates a 90deg gradient with the current text color (<code>currentColor</code>).</li>
|
||||||
|
<li>The <code>background-*</code> properties size the gradient as 1x1px at the bottom and repeats it along the x-axis.</li>
|
||||||
|
<li>The <code>::selection</code> pseudo selector ensures the text shadow does not interfere with text selection.
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
94.8%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-textshadow" target="_blank">https://caniuse.com/#feat=css-textshadow</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=css-gradients" target="_blank">https://caniuse.com/#feat=css-gradients</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="shape-separator">Shape separator</h3>
|
||||||
|
<p>Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="shape-separator"></div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.shape-separator {
|
||||||
|
position: relative;
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
|
.shape-separator::after {
|
||||||
|
content: '';
|
||||||
|
background-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxLjQxNCI+PHBhdGggZD0iTTEyIDEybDEyIDEySDBsMTItMTJ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+);
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>position: relative</code> on the element establishes a Cartesian positioning context for psuedo elements.</li>
|
||||||
|
<li><code>::after</code> defines a pseudo element.</li>
|
||||||
|
<li><code>background-image: url(...)</code> adds the SVG shape (a 24x24 triangle in base64 format) as the background image of the psuedo element, which repeats by default. It must be the same color as the block that is being separated.
|
||||||
|
</li>
|
||||||
|
<li><code>position: absolute</code> takes the pseudo element out of the flow of the document and positions it in relation to the parent.</li>
|
||||||
|
<li><code>width: 100%</code> ensures the element stretches the entire width of its parent.</li>
|
||||||
|
<li><code>height: 24px</code> is the same height as the shape.</li>
|
||||||
|
<li><code>bottom: 0</code> positions the pseudo element at the bottom of the parent.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
98.0%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=svg" target="_blank">https://caniuse.com/#feat=svg</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="system-font-stack">System font stack</h3>
|
||||||
|
<p>Uses the native font of the operating system to get close to a native app feel.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="system-font-stack">This text uses the system font.</p>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.system-font-stack {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<p>The browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).</p>
|
||||||
|
<ol>
|
||||||
|
<li><code>-apple-system</code> is San Francisco, used on iOS and macOS (not Chrome however)</li>
|
||||||
|
<li><code>BlinkMacSystemFont</code> is San Francisco, used on macOS Chrome</li>
|
||||||
|
<li><code>Segoe UI</code> is used on Windows 10</li>
|
||||||
|
<li><code>Roboto</code> is used on Android</li>
|
||||||
|
<li><code>Oxygen-Sans</code> is used on GNU+Linux</li>
|
||||||
|
<li><code>Ubuntu</code> is used on Linux</li>
|
||||||
|
<li><code>"Helvetica Neue"</code> and <code>Helvetica</code> is used on macOS 10.10 and below (wrapped in quotes because it has a space)</li>
|
||||||
|
<li><code>Arial</code> is a font widely supported by all operating systems</li>
|
||||||
|
<li><code>sans-serif</code> is the fallback sans-serif font if none of the other fonts are supported</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
99+%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="triangle">Triangle</h3>
|
||||||
|
<p>Creates a triangle shape with pure CSS.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="triangle"></div>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.triangle {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-top: 20px solid #333;
|
||||||
|
border-left: 20px solid transparent;
|
||||||
|
border-right: 20px solid transparent;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<p>
|
||||||
|
<a href="https://stackoverflow.com/q/7073484" target="_blank">View this link for a detailed explanation.</a>
|
||||||
|
</p>
|
||||||
|
<p>The color of the border is the color of the triangle. The side the triangle tip points corresponds to the opposite <code>border-*</code> property. For example, a color on <code>border-top</code> means the arrow points downward.</p>
|
||||||
|
<p>Experiment with the <code>px</code> values to change the proportion of the triangle.</p>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
99+%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
</div>
|
||||||
|
<div class="snippet">
|
||||||
|
<h3 id="truncate-text">Truncate text</h3>
|
||||||
|
<p>If the text is longer than one line, it will be truncated and end with an ellipsis <code>...</code>.</p>
|
||||||
|
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="truncate-text">If I exceed one line's width, I will be truncated.</p>
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.truncate-text {
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
</code></pre>
|
||||||
|
<h4 data-type="Demo">Demo</h4>
|
||||||
|
<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>
|
||||||
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
|
<ol>
|
||||||
|
<li><code>overflow: hidden</code> prevents the text from overflowing its dimensions (for a block, 100% width and auto height).</li>
|
||||||
|
<li><code>white-space: nowrap</code> prevents the text from exceeding one line in height.</li>
|
||||||
|
<li><code>text-overflow: ellipsis</code> makes it so that if the text exceeds its dimensions, it will end with an ellipsis.</li>
|
||||||
|
</ol>
|
||||||
|
<h4 data-type="Browser support">Browser support</h4>
|
||||||
|
<div>
|
||||||
|
<div class="snippet__browser-support">
|
||||||
|
98.1%
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p><span class="snippet__support-note">✅ No caveats.</span></p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://caniuse.com/#feat=text-overflow" target="_blank">https://caniuse.com/#feat=text-overflow</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
<footer class="footer"></footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1621
dist/719042b6d7879d0a403a9eaac2211738.css
vendored
Normal file
1621
dist/719042b6d7879d0a403a9eaac2211738.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1479
dist/719042b6d7879d0a403a9eaac2211738.js
vendored
Normal file
1479
dist/719042b6d7879d0a403a9eaac2211738.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
dist/719042b6d7879d0a403a9eaac2211738.map
vendored
Normal file
1
dist/719042b6d7879d0a403a9eaac2211738.map
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
dist/ac46b6c579212c73b4f2afaa428f354c.png
vendored
Normal file
BIN
dist/ac46b6c579212c73b4f2afaa428f354c.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@ -852,7 +852,7 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<h4 data-type="Explanation">Explanation</h4>
|
<h4 data-type="Explanation">Explanation</h4>
|
||||||
<p>The browser looks for each successive font, preferring the first one if possible, and falls back to the next of it cannot find the font (on the system or defined in CSS).</p>
|
<p>The browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).</p>
|
||||||
<ol>
|
<ol>
|
||||||
<li><code>-apple-system</code> is San Francisco, used on iOS and macOS (not Chrome however)</li>
|
<li><code>-apple-system</code> is San Francisco, used on iOS and macOS (not Chrome however)</li>
|
||||||
<li><code>BlinkMacSystemFont</code> is San Francisco, used on macOS Chrome</li>
|
<li><code>BlinkMacSystemFont</code> is San Francisco, used on macOS Chrome</li>
|
||||||
|
|||||||
@ -31,7 +31,7 @@ Uses the native font of the operating system to get close to a native app feel.
|
|||||||
#### Explanation
|
#### Explanation
|
||||||
|
|
||||||
The browser looks for each successive font, preferring the first one if possible, and
|
The browser looks for each successive font, preferring the first one if possible, and
|
||||||
falls back to the next of it cannot find the font (on the system or defined in CSS).
|
falls back to the next if it cannot find the font (on the system or defined in CSS).
|
||||||
|
|
||||||
1. `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however)
|
1. `-apple-system` is San Francisco, used on iOS and macOS (not Chrome however)
|
||||||
2. `BlinkMacSystemFont` is San Francisco, used on macOS Chrome
|
2. `BlinkMacSystemFont` is San Francisco, used on macOS Chrome
|
||||||
|
|||||||
Reference in New Issue
Block a user