Travis build: 97 [cron]
This commit is contained in:
@ -111,9 +111,9 @@ li::before {
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="counter.md"> <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> </div> <h4>Explanation</h4> <p>You can create a ordered list using any type of HTML.</p> <ol> <li> <p><code>counter-reset</code> Initializes a counter, the value is the name of the counter. By default, the counter starts at 0. This property can also be used to change its value to any specific number.</p> </li> <li> <p><code>counter-increment</code> Used in element that will be countable. Once <code>counter-reset</code> initialized, a counter's value can be increased or decreased.</p> </li> <li> <p><code>counter(name, style)</code> Displays the value of a section counter. Generally used in a <code>content</code> property. This function can receive two parameters, the first as the name of the counter and the second one can be <code>decimal</code> or <code>upper-roman</code> (<code>decimal</code> by default).</p> </li> <li> <p><code>counters(counter, string, style)</code> Displays the value of a section counter. Generally used in a <code>content</code> 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 <code>decimal</code> or <code>upper-roman</code> (<code>decimal</code> by default).</p> </li> <li> <p>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 <code>counters()</code> function, separating text can be inserted between different levels of nested counters.</p> </li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 95.9% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <ul> <li><a href="https://caniuse.com/#feat=css-counters" target="_blank">https://caniuse.com/#feat=css-counters</a></li> </ul> </div> <div class="snippet"> <h3 id="custom-scrollbar"><span>Custom scrollbar</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="custom-scrollbar">
|
||||
<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>
|
||||
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>
|
||||
@ -162,9 +162,7 @@ li::before {
|
||||
user-select: none;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="disable-selection.md"> <p>You can select me.</p> <p class="unselectable">You can't select me!</p> </div> <h4>Explanation</h4> <p><code>user-select: none</code> specifies that the text cannot be selected.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 89.2% </div> </div> <p><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></p> <ul> <li><a href="https://caniuse.com/#feat=user-select-none" target="_blank">https://caniuse.com/#feat=user-select-none</a></li> </ul> </div> <div class="snippet"> <h3 id="display-table-centering"><span>Display table centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Vertically and horizontally centers a child element within its parent element using <code>display: table</code> (as an alternative to <code>flexbox</code>).</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="container">
|
||||
<div class="center">
|
||||
<span>Centered content</span>
|
||||
</div>
|
||||
<div class="center"><span>Centered content</span></div>
|
||||
</div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.container {
|
||||
border: 1px solid #333;
|
||||
@ -181,7 +179,7 @@ li::before {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="display-table-centering.md"> <div class="container"> <div class="center"> <span>Centered content</span> </div> </div> </div> <h4>Explanation</h4> <ol> <li><code>display: table</code> on '.center' allows the element to behave like a <code><table></code> HTML element.</li> <li>100% height and width on '.center' allows the element to fill the available space within its parent element.</li> <li><code>display: table-cell</code> on '.center > span' allows the element to behave like an HTML element.</li> <li><code>text-align: center</code> on '.center > span' centers the child element horizontally.</li> <li><code>vertical-align: middle</code> on '.center > span' centers the child element vertically.</li> </ol> <p>The outer parent ('.container' in this case) must have a fixed height and width.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 99+% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <ul> <li><a href="https://caniuse.com/#search=display%3A%20table" target="_blank">https://caniuse.com/#search=display%3A%20table</a></li> </ul> </div> <div class="snippet"> <h3 id="donut-spinner"><span>Donut spinner</span><span class="tags__tag snippet__tag" data-type="animation"><i data-feather="loader"></i>animation</span></h3> <p>Creates a donut spinner that can be used to indicate the loading of content.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="donut"></div>
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="display-table-centering.md"> <div class="container"> <div class="center"><span>Centered content</span></div> </div> </div> <h4>Explanation</h4> <ol> <li><code>display: table</code> on '.center' allows the element to behave like a <code><table></code> HTML element.</li> <li>100% height and width on '.center' allows the element to fill the available space within its parent element.</li> <li><code>display: table-cell</code> on '.center > span' allows the element to behave like an HTML element.</li> <li><code>text-align: center</code> on '.center > span' centers the child element horizontally.</li> <li><code>vertical-align: middle</code> on '.center > span' centers the child element vertically.</li> </ol> <p>The outer parent ('.container' in this case) must have a fixed height and width.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 99+% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <ul> <li><a href="https://caniuse.com/#search=display%3A%20table" target="_blank">https://caniuse.com/#search=display%3A%20table</a></li> </ul> </div> <div class="snippet"> <h3 id="donut-spinner"><span>Donut spinner</span><span class="tags__tag snippet__tag" data-type="animation"><i data-feather="loader"></i>animation</span></h3> <p>Creates a donut spinner that can be used to indicate the loading of content.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="donut"></div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">@keyframes donut-spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
@ -270,8 +268,8 @@ li::before {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="evenly-distributed-children.md"> <div class="evenly-distributed-children"> <p>Item1</p> <p>Item2</p> <p>Item3</p> </div> </div> <h4>Explanation</h4> <ol> <li><code>display: flex</code> enables flexbox.</li> <li><code>justify-content: space-between</code> evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.</li> </ol> <p>Alternatively, use <code>justify-content: space-around</code> to distribute the children with space around them, rather than between them.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 95.5% </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="fit-image-in-container"><span>Fit image in container</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the <code>background-size</code> property.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><img class="image image-contain" src="https://picsum.photos/600/200">
|
||||
<img class="image image-cover" src="https://picsum.photos/600/200">
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="evenly-distributed-children.md"> <div class="evenly-distributed-children"> <p>Item1</p> <p>Item2</p> <p>Item3</p> </div> </div> <h4>Explanation</h4> <ol> <li><code>display: flex</code> enables flexbox.</li> <li><code>justify-content: space-between</code> evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.</li> </ol> <p>Alternatively, use <code>justify-content: space-around</code> to distribute the children with space around them, rather than between them.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 95.5% </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="fit-image-in-container"><span>Fit image in container</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the <code>background-size</code> property.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><img class="image image-contain" src="https://picsum.photos/600/200" />
|
||||
<img class="image image-cover" src="https://picsum.photos/600/200" />
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.image {
|
||||
background: #34495e;
|
||||
border: 1px solid #34495e;
|
||||
@ -286,9 +284,7 @@ li::before {
|
||||
object-fit: cover;
|
||||
object-position: right top;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="fit-image-in-container.md"><img class="image image-contain" src="https://picsum.photos/600/200"> <img class="image image-cover" src="https://picsum.photos/600/200"></div> <h4>Explanation</h4> <ul> <li><code>object-fit: contain</code> fits the entire image within the container while preserving its aspect ratio.</li> <li><code>object-fit: cover</code> fills the container with the image while preserving its aspect ratio.</li> <li><code>object-position: [x] [y]</code> positions the image within the container.</li> </ul> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 91.5% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <ul> <li><a href="https://caniuse.com/#feat=object-fit" target="_blank">https://caniuse.com/#feat=object-fit</a></li> </ul> </div> <div class="snippet"> <h3 id="flexbox-centering"><span>Flexbox centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Horizontally and vertically centers a child element within a parent element using <code>flexbox</code>.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="flexbox-centering">
|
||||
<div class="child">Centered content.</div>
|
||||
</div>
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="fit-image-in-container.md"><img class="image image-contain" src="https://picsum.photos/600/200"> <img class="image image-cover" src="https://picsum.photos/600/200"></div> <h4>Explanation</h4> <ul> <li><code>object-fit: contain</code> fits the entire image within the container while preserving its aspect ratio.</li> <li><code>object-fit: cover</code> fills the container with the image while preserving its aspect ratio.</li> <li><code>object-position: [x] [y]</code> positions the image within the container.</li> </ul> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 91.5% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <ul> <li><a href="https://caniuse.com/#feat=object-fit" target="_blank">https://caniuse.com/#feat=object-fit</a></li> </ul> </div> <div class="snippet"> <h3 id="flexbox-centering"><span>Flexbox centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Horizontally and vertically centers a child element within a parent element using <code>flexbox</code>.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="flexbox-centering"><div class="child">Centered content.</div></div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.flexbox-centering {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
@ -301,9 +297,7 @@ li::before {
|
||||
-webkit-text-fill-color: transparent;
|
||||
-webkit-background-clip: text;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="gradient-text.md"> <p class="gradient-text">Gradient text</p> </div> <h4>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>Browser support</h4> <div> <div class="snippet__browser-support"> 90.1% </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="grid-centering"><span>Grid centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Horizontally and vertically centers a child element within a parent element using <code>grid</code>.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="grid-centering">
|
||||
<div class="child">Centered content.</div>
|
||||
</div>
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="gradient-text.md"> <p class="gradient-text">Gradient text</p> </div> <h4>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>Browser support</h4> <div> <div class="snippet__browser-support"> 90.1% </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="grid-centering"><span>Grid centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Horizontally and vertically centers a child element within a parent element using <code>grid</code>.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="grid-centering"><div class="child">Centered content.</div></div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.grid-centering {
|
||||
display: grid;
|
||||
justify-content: center;
|
||||
@ -385,9 +379,7 @@ body {
|
||||
background-color: tomato;
|
||||
flex: 1;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="last-item-with-remaining-available-height.md"> <div class="container"> <div>Div 1</div> <div>Div 2</div> <div>Div 3</div> </div> </div> <h4>Explanation</h4> <ol> <li><code>height: 100%</code> set the height of container as viewport height.</li> <li><code>display: flex</code> enables flexbox.</li> <li><code>flex-direction: column</code> set the direction of flex items' order from top to down.</li> <li><code>flex-grow: 1</code> the flexbox will apply remaining available space of container to last child element.</li> </ol> <p>The parent must have a viewport height. <code>flex-grow: 1</code> could be applied to the first or second element, which will have all available space.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 95.5% </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"><span>Mouse cursor gradient tracking</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>A hover effect where the gradient follows the mouse cursor.</p> <p><small class="snippet__credit"><strong>Credit:</strong> <a href="https://codepen.io/electerious/pen/MQrRxX" target="_blank">Tobias Reich</a></small></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>Demo</h4> <div class="snippet-demo" data-scope="last-item-with-remaining-available-height.md"> <div class="container"> <div>Div 1</div> <div>Div 2</div> <div>Div 3</div> </div> </div> <h4>Explanation</h4> <ol> <li><code>height: 100%</code> set the height of container as viewport height.</li> <li><code>display: flex</code> enables flexbox.</li> <li><code>flex-direction: column</code> set the direction of flex items' order from top to down.</li> <li><code>flex-grow: 1</code> the flexbox will apply remaining available space of container to last child element.</li> </ol> <p>The parent must have a viewport height. <code>flex-grow: 1</code> could be applied to the first or second element, which will have all available space.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 95.5% </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"><span>Mouse cursor gradient tracking</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>A hover effect where the gradient follows the mouse cursor.</p> <p><small class="snippet__credit"><strong>Credit:</strong> <a href="https://codepen.io/electerious/pen/MQrRxX" target="_blank">Tobias Reich</a></small></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: #7983ff;
|
||||
@ -424,7 +416,7 @@ btn.onmousemove = function(e) {
|
||||
btn.style.setProperty('--x', x + 'px')
|
||||
btn.style.setProperty('--y', y + 'px')
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="mouse-cursor-gradient-tracking.md"><button class="mouse-cursor-gradient-tracking"> <span>Hover me</span> </button></div> <script>!function(){var e=document.querySelector(".el"),t=e.scrollHeight;e.style.setProperty("--max-height",t+"px")}(),function(){var e=document.querySelector(".mouse-cursor-gradient-tracking");e.onmousemove=function(t){var o=t.pageX-e.offsetLeft-e.offsetParent.offsetLeft,r=t.pageY-e.offsetTop-e.offsetParent.offsetTop;e.style.setProperty("--x",o+"px"),e.style.setProperty("--y",r+"px")}}();</script> <h4>Explanation</h4> <p><em>TODO</em></p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 87.6% </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="not-selector"><span>:not selector</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>The <code>:not</code> psuedo selector is useful for styling a group of elements, while leaving the last (or specified) element unstyled.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><ul class="css-not-selector-shortcut">
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="mouse-cursor-gradient-tracking.md"><button class="mouse-cursor-gradient-tracking"><span>Hover me</span></button></div> <script>!function(){var e=document.querySelector(".el"),t=e.scrollHeight;e.style.setProperty("--max-height",t+"px")}(),function(){var e=document.querySelector(".mouse-cursor-gradient-tracking");e.onmousemove=function(t){var o=t.pageX-e.offsetLeft-e.offsetParent.offsetLeft,r=t.pageY-e.offsetTop-e.offsetParent.offsetTop;e.style.setProperty("--x",o+"px"),e.style.setProperty("--y",r+"px")}}();</script> <h4>Explanation</h4> <p><em>TODO</em></p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 87.6% </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="not-selector"><span>:not selector</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>The <code>:not</code> psuedo selector is useful for styling a group of elements, while leaving the last (or specified) element unstyled.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><ul class="css-not-selector-shortcut">
|
||||
<li>One</li>
|
||||
<li>Two</li>
|
||||
<li>Three</li>
|
||||
@ -445,8 +437,7 @@ li:not(:last-child) {
|
||||
border-right: 2px solid #d2d5e4;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="not-selector.md"> <ul class="css-not-selector-shortcut"> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> </ul> </div> <h4>Explanation</h4> <p><code>li:not(:last-child)</code> specifies that the styles should apply to all <code>li</code> elements except the <code>:last-child</code>.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 95.9% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <ul> <li><a href="https://caniuse.com/#feat=css-sel3" target="_blank">https://caniuse.com/#feat=css-sel3</a></li> </ul> </div> <div class="snippet"> <h3 id="offscreen"><span>Offscreen</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>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 (<a href="https://adata.org/learn-about-ada" target="_blank">ADA</a>) development when more context is needed for visually-impaired users. As an alternative to <code>display: none</code> which is not readable by screen readers or <code>visibility: hidden</code> which takes up physical space in the DOM.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><a class="button" href="http://pantswebsite.com">
|
||||
Learn More
|
||||
<span class="offscreen"> about pants</span>
|
||||
Learn More <span class="offscreen"> about pants</span>
|
||||
</a>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.offscreen {
|
||||
border: 0;
|
||||
@ -460,13 +451,13 @@ li:not(:last-child) {
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="offscreen.md"><a class="button" href="http://pantswebsite.com"> Learn More <span class="offscreen"> about pants</span> </a></div> <h4>Explanation</h4> <ol> <li>Remove all borders.</li> <li>Use <code>clip</code> to indicate that no part of the element should be shown.</li> <li>Make the height and width of the element 1px.</li> <li>Negate the elements height and width using <code>margin: -1px</code>.</li> <li>Hide the element's overflow.</li> <li>Remove all padding.</li> <li>Position the element absolutely so that it does not take up space in the DOM.</li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 99+% </div> </div> <p><span class="snippet__support-note">✅ No caveats.</span></p> <p>(Although <code>clip</code> technically has been depreciated, the newer <code>clip-path</code> currently has very limited browser support.)</p> <ul> <li><a href="https://caniuse.com/#search=clip" target="_blank">https://caniuse.com/#search=clip</a></li> </ul> </div> <div class="snippet"> <h3 id="overflow-scroll-gradient"><span>Overflow scroll gradient</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></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">
|
||||
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>
|
||||
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>
|
||||
@ -493,11 +484,7 @@ li:not(:last-child) {
|
||||
padding: 15px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="overflow-scroll-gradient.md"> <div class="overflow-scroll-gradient"> <div class="overflow-scroll-gradient__scroller"> 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> </div> <h4>Explanation</h4> <ol> <li><code>position: relative</code> on the parent establishes a Cartesian positioning context for pseudo-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: 240px</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 pseudo-element, which should be kept relatively small.</li> <li><code>bottom: 0</code> positions the pseudo-element at the bottom of the parent.</li> <li><code>pointer-events: none</code> specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.</li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 93.5% </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"><span>Popout menu</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>Reveals an interactive popout menu on hover and focus.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="reference" tabindex="0">
|
||||
<div class="popout-menu">
|
||||
Popout menu
|
||||
</div>
|
||||
</div>
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="overflow-scroll-gradient.md"> <div class="overflow-scroll-gradient"> <div class="overflow-scroll-gradient__scroller"> 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> </div> <h4>Explanation</h4> <ol> <li><code>position: relative</code> on the parent establishes a Cartesian positioning context for pseudo-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: 240px</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 pseudo-element, which should be kept relatively small.</li> <li><code>bottom: 0</code> positions the pseudo-element at the bottom of the parent.</li> <li><code>pointer-events: none</code> specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.</li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 93.5% </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"><span>Popout menu</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>Reveals an interactive popout menu on hover and focus.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="reference" tabindex="0"><div class="popout-menu">Popout menu</div></div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.reference {
|
||||
position: relative;
|
||||
background: tomato;
|
||||
@ -517,7 +504,7 @@ li:not(:last-child) {
|
||||
.reference:focus-within > .popout-menu {
|
||||
visibility: visible;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="popout-menu.md"> <div class="reference" tabindex="0"> <div class="popout-menu"> Popout menu </div> </div> </div> <h4>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> <li><code>.reference:focus > .popout-menu</code> means that when <code>.reference</code> is focused, the popout would be shown.</li> <li><code>.reference:focus-within > .popout-menu</code> ensures that the popout is shown when the focus is <em>within</em> the reference.</li> </ol> <h4>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"><span>Pretty text underline</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>A nicer alternative to <code>text-decoration: underline</code> or <code><u></u></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>Demo</h4> <div class="snippet-demo" data-scope="popout-menu.md"> <div class="reference" tabindex="0"> <div class="popout-menu">Popout menu</div> </div> </div> <h4>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> <li><code>.reference:focus > .popout-menu</code> means that when <code>.reference</code> is focused, the popout would be shown.</li> <li><code>.reference:focus-within > .popout-menu</code> ensures that the popout is shown when the focus is <em>within</em> the reference.</li> </ol> <h4>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"><span>Pretty text underline</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>A nicer alternative to <code>text-decoration: underline</code> or <code><u></u></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;
|
||||
text-shadow: 1px 1px #f5f6f9, -1px 1px #f5f6f9, -1px -1px #f5f6f9, 1px -1px #f5f6f9;
|
||||
@ -536,12 +523,16 @@ li:not(:last-child) {
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="pretty-text-underline.md"> <p class="pretty-text-underline">Pretty text underline without clipping descending letters.</p> </div> <h4>Explanation</h4> <ol> <li><code>text-shadow</code> 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 <code>px</code> size. Additional values can create an even thicker shadow, and subpixel values can also be used.</li> <li><code>background-image: linear-gradient(...)</code> creates a 90deg gradient using the text color (<code>currentColor</code>).</li> <li>The <code>background-*</code> 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.</li> <li>The <code>::selection</code> pseudo selector rule ensures the text shadow does not interfere with text selection.</li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 93.5% </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="reset-all-styles"><span>Reset all styles</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3> <p>Resets all styles to default values with one property. This will not affect <code>direction</code> and <code>unicode-bidi</code> properties.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="reset-all-styles">
|
||||
<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>
|
||||
<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>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.reset-all-styles {
|
||||
all: initial;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="reset-all-styles.md"> <div class="reset-all-styles"> <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> </div> <h4>Explanation</h4> <p>The <code>all</code> property allows you to reset all styles (inherited or not) to default values.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 87.2% </div> </div> <p><span class="snippet__support-note">⚠️ MS Edge status is under consideration.</span></p> <ul> <li><a href="https://caniuse.com/#feat=css-all" target="_blank">https://caniuse.com/#feat=css-all</a></li> </ul> </div> <div class="snippet"> <h3 id="shape-separator"><span>Shape separator</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></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>Demo</h4> <div class="snippet-demo" data-scope="reset-all-styles.md"> <div class="reset-all-styles"> <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> </div> <h4>Explanation</h4> <p>The <code>all</code> property allows you to reset all styles (inherited or not) to default values.</p> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 87.2% </div> </div> <p><span class="snippet__support-note">⚠️ MS Edge status is under consideration.</span></p> <ul> <li><a href="https://caniuse.com/#feat=css-all" target="_blank">https://caniuse.com/#feat=css-all</a></li> </ul> </div> <div class="snippet"> <h3 id="shape-separator"><span>Shape separator</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></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;
|
||||
@ -556,12 +547,8 @@ li:not(:last-child) {
|
||||
bottom: 0;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="shape-separator.md"> <div class="shape-separator"></div> </div> <h4>Explanation</h4> <ol> <li><code>position: relative</code> on the element establishes a Cartesian positioning context for pseudo elements.</li> <li><code>::after</code> defines a pseudo element.</li> <li><code>background-image: url(...)</code> 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 <a href="http://yoksel.github.io/url-encoder/" target="_blank">the URL-encoder for SVG</a>.</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: 12px</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>Browser support</h4> <div> <div class="snippet__browser-support"> 95.7% </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="sibling-fade"><span>Sibling fade</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>Fades out the siblings of a hovered item.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="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>
|
||||
<span>Item 1</span> <span>Item 2</span> <span>Item 3</span> <span>Item 4</span>
|
||||
<span>Item 5</span> <span>Item 6</span>
|
||||
</div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">span {
|
||||
padding: 0 1rem;
|
||||
@ -575,8 +562,7 @@ li:not(:last-child) {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,
|
||||
Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="system-font-stack.md"> <p class="system-font-stack">This text uses the system font.</p> </div> <h4>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>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="toggle-switch"><span>Toggle switch</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>Creates a toggle switch with CSS only.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><input type="checkbox" id="toggle" class="offscreen" />
|
||||
<label for="toggle" class="switch"></label>
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="system-font-stack.md"> <p class="system-font-stack">This text uses the system font.</p> </div> <h4>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>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="toggle-switch"><span>Toggle switch</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3> <p>Creates a toggle switch with CSS only.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><input type="checkbox" id="toggle" class="offscreen" /> <label for="toggle" class="switch"></label>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
@ -607,9 +593,7 @@ input[type='checkbox']:checked + .switch {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
}
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="toggle-switch.md"><input type="checkbox" id="toggle" class="offscreen"> <label for="toggle" class="switch"></label></div> <h4>Explanation</h4> <p>This effect is styling only the <code><label></code> element to look like a toggle switch, and hiding the actual <code><input></code> checkbox by positioning it offscreen. When clicking the label associated with the <code><input></code> element, it sets the <code><input></code> checkbox into the <code>:checked</code> state.</p> <ol> <li>The <code>for</code> attribute associates the <code><label></code> with the appropriate <code><input></code> checkbox element by its <code>id</code>.</li> <li><code>.switch::after</code> defines a pseudo-element for the <code><label></code> to create the circular knob.</li> <li><code>input[type='checkbox']:checked + .switch::after</code> targets the <code><label></code>'s pseudo-element's style when the checkbox is <code>checked</code>.</li> <li><code>transform: translateX(20px)</code> moves the pseudo-element (knob) 20px to the right when the checkbox is <code>checked</code>.</li> <li><code>background-color: #7983ff;</code> sets the background-color of the switch to a different color when the checkbox is <code>checked</code>.</li> <li><code>.offscreen</code> moves the <code><input></code> 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.</li> <li><code>transition: all 0.3s</code> specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the <code><label></code>'s <code>background-color</code> and the pseudo-element's <code>transform</code> property when the checkbox is checked.</li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 93.7% </div> </div> <p><span class="snippet__support-note">⚠️ Requires prefixes for full support.</span></p> <ul> <li><a href="https://caniuse.com/#feat=transforms2d" target="_blank">https://caniuse.com/#feat=transforms2d</a></li> </ul> </div> <div class="snippet"> <h3 id="transform-centering"><span>Transform centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Vertically and horizontally centers a child element within its parent element using <code>position: absolute</code> and <code>transform: translate()</code> (as an alternative to <code>flexbox</code> or <code>display: table</code>). Similar to <code>flexbox</code>, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="parent">
|
||||
<div class="child">Centered content</div>
|
||||
</div>
|
||||
</code></pre> <h4>Demo</h4> <div class="snippet-demo" data-scope="toggle-switch.md"><input type="checkbox" id="toggle" class="offscreen"> <label for="toggle" class="switch"></label></div> <h4>Explanation</h4> <p>This effect is styling only the <code><label></code> element to look like a toggle switch, and hiding the actual <code><input></code> checkbox by positioning it offscreen. When clicking the label associated with the <code><input></code> element, it sets the <code><input></code> checkbox into the <code>:checked</code> state.</p> <ol> <li>The <code>for</code> attribute associates the <code><label></code> with the appropriate <code><input></code> checkbox element by its <code>id</code>.</li> <li><code>.switch::after</code> defines a pseudo-element for the <code><label></code> to create the circular knob.</li> <li><code>input[type='checkbox']:checked + .switch::after</code> targets the <code><label></code>'s pseudo-element's style when the checkbox is <code>checked</code>.</li> <li><code>transform: translateX(20px)</code> moves the pseudo-element (knob) 20px to the right when the checkbox is <code>checked</code>.</li> <li><code>background-color: #7983ff;</code> sets the background-color of the switch to a different color when the checkbox is <code>checked</code>.</li> <li><code>.offscreen</code> moves the <code><input></code> 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.</li> <li><code>transition: all 0.3s</code> specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the <code><label></code>'s <code>background-color</code> and the pseudo-element's <code>transform</code> property when the checkbox is checked.</li> </ol> <h4>Browser support</h4> <div> <div class="snippet__browser-support"> 93.7% </div> </div> <p><span class="snippet__support-note">⚠️ Requires prefixes for full support.</span></p> <ul> <li><a href="https://caniuse.com/#feat=transforms2d" target="_blank">https://caniuse.com/#feat=transforms2d</a></li> </ul> </div> <div class="snippet"> <h3 id="transform-centering"><span>Transform centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3> <p>Vertically and horizontally centers a child element within its parent element using <code>position: absolute</code> and <code>transform: translate()</code> (as an alternative to <code>flexbox</code> or <code>display: table</code>). Similar to <code>flexbox</code>, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.</p> <h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="parent"><div class="child">Centered content</div></div>
|
||||
</code></pre> <h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.parent {
|
||||
border: 1px solid #333;
|
||||
height: 250px;
|
||||
|
||||
Reference in New Issue
Block a user