Merge branch 'master' into copyToClipboard
This commit is contained in:
113
snippets/bouncing-loader.md
Normal file
113
snippets/bouncing-loader.md
Normal file
@ -0,0 +1,113 @@
|
||||
### Bouncing loader
|
||||
|
||||
Creates a bouncing loader animation.
|
||||
|
||||
#### HTML
|
||||
|
||||
```html
|
||||
<div class="bouncing-loader">
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### CSS
|
||||
|
||||
```css
|
||||
@keyframes bouncing-loader {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 0.1;
|
||||
transform: translateY(-1rem);
|
||||
}
|
||||
}
|
||||
.bouncing-loader {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.bouncing-loader > div {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin: 3rem 0.2rem;
|
||||
background: #8385aa;
|
||||
border-radius: 50%;
|
||||
animation: bouncing-loader 0.6s infinite alternate;
|
||||
}
|
||||
.bouncing-loader > div:nth-of-type(2) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
.bouncing-loader > div:nth-of-type(3) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
```
|
||||
|
||||
#### Demo
|
||||
|
||||
<div class="snippet-demo">
|
||||
<div class="snippet-demo__bouncing-loader">
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@keyframes bouncing-loader {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 0.1;
|
||||
transform: translateY(-1rem);
|
||||
}
|
||||
}
|
||||
.snippet-demo__bouncing-loader {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.snippet-demo__bouncing-loader > div {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin: 3rem 0.2rem;
|
||||
background: #8385aa;
|
||||
border-radius: 50%;
|
||||
animation: bouncing-loader 0.6s infinite alternate;
|
||||
}
|
||||
.snippet-demo__bouncing-loader > div:nth-child(2) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
.snippet-demo__bouncing-loader > div:nth-child(3) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
</style>
|
||||
|
||||
#### Explanation
|
||||
|
||||
Note: `1rem` is usually `16px`.
|
||||
|
||||
1. `@keyframes` defines an animation that has two states, where the element changes `opacity`, and is translated up on the 2D plane using `transform: translateY()`.
|
||||
|
||||
2. `.bouncing-loader` is the parent container of the bouncing circles and uses `display: flex`
|
||||
and `justify-content: center` to position them in the in the center.
|
||||
|
||||
3. Using `.bouncing-loader > div`, we target the three child `div`s of the parent to be styled. The `div`s are given a width and height of `1rem`, using `border-radius: 50%` to turn them from squares to circles.
|
||||
|
||||
4. `margin: 3rem 0.2rem` specifies that each circle has a top/bottom margin of `3rem` and left/right margin
|
||||
of `0.2rem` so that they do not directly touch each other, giving them some breathing room.
|
||||
|
||||
5. `animation` is a shorthand property for the various animation properties: `animation-name`, `animation-duration`, `animation-iteration-count`, `animation-direction` are used.
|
||||
|
||||
6. `animation-delay` is used on the second and third `div` respectively, so that each element does not start the animation at the same time.
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-animation
|
||||
|
||||
<!-- tags: animation -->
|
||||
@ -44,3 +44,5 @@ html {
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css3-boxsizing
|
||||
|
||||
<!-- tags: layout -->
|
||||
|
||||
50
snippets/circle.md
Normal file
50
snippets/circle.md
Normal file
@ -0,0 +1,50 @@
|
||||
### Circle
|
||||
|
||||
Creates a circle shape with pure CSS.
|
||||
|
||||
#### HTML
|
||||
|
||||
```html
|
||||
<div class="circle"></div>
|
||||
```
|
||||
|
||||
#### CSS
|
||||
|
||||
```css
|
||||
.circle {
|
||||
border-radius: 50%;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
background: #333;
|
||||
}
|
||||
```
|
||||
|
||||
#### Demo
|
||||
|
||||
<div class="snippet-demo">
|
||||
<div class="snippet-demo__circle"></div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.snippet-demo__circle {
|
||||
border-radius: 50%;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
background: #333;
|
||||
}
|
||||
</style>
|
||||
|
||||
#### Explanation
|
||||
|
||||
`border-radius: 50%` curves the borders of an element to create a circle.
|
||||
|
||||
Since a circle has the same radius at any given point, the `width` and `height` must be the same. Differing
|
||||
values will create an ellipse.
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=border-radius
|
||||
|
||||
<!-- tags: visual -->
|
||||
@ -18,7 +18,7 @@ Ensures that an element self-clears its children.
|
||||
|
||||
```css
|
||||
.clearfix::after {
|
||||
content: "";
|
||||
content: '';
|
||||
display: block;
|
||||
clear: both;
|
||||
}
|
||||
@ -59,4 +59,6 @@ Ensures that an element self-clears its children.
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
<span class="snippet__support-note">⚠️ For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).</span>
|
||||
|
||||
<!-- tags: layout -->
|
||||
|
||||
@ -43,3 +43,5 @@ causes an element's height to become a percentage of its parent's width, i.e. `5
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">⚠️ `padding-top` pushes any content within the element to the bottom.</span>
|
||||
|
||||
<!-- tags: layout -->
|
||||
|
||||
@ -19,13 +19,13 @@ Customizes the scrollbar style for the document and elements with scrollable ove
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
|
||||
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
border-radius: 10px;
|
||||
box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
|
||||
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
/* Scrollable element */
|
||||
@ -80,3 +80,5 @@ There are many other pseudo-elements that you can use to style scrollbars. For m
|
||||
<span class="snippet__support-note">⚠️ Scrollbar styling doesn't appear to be on any standards track.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-scrollbar
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -48,3 +48,5 @@ Changes the styling of text selection.
|
||||
in any specification.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-selection
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -37,5 +37,8 @@ Makes the content unselectable.
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
|
||||
<span class="snippet__support-note">⚠️ This is not a secure method to prevent users from copying content.</span>
|
||||
|
||||
* https://caniuse.com/#feat=user-select-none
|
||||
|
||||
<!-- tags: interactivity -->
|
||||
|
||||
@ -12,8 +12,12 @@ Creates a donut spinner that can be used to indicate the loading of content.
|
||||
|
||||
```css
|
||||
@keyframes donut-spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.donut {
|
||||
display: inline-block;
|
||||
@ -59,3 +63,5 @@ serve as the loading indicator for the donut. Use `animation` to rotate the elem
|
||||
|
||||
* https://caniuse.com/#feat=css-animation
|
||||
* https://caniuse.com/#feat=transforms2d
|
||||
|
||||
<!-- tags: animation -->
|
||||
|
||||
@ -104,3 +104,5 @@ The variables are defined globally within the `:root` CSS pseudo-class which mat
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-variables
|
||||
|
||||
<!-- tags: animation -->
|
||||
|
||||
@ -49,3 +49,5 @@ of the background.
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-textshadow
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -51,3 +51,5 @@ Alternatively, use `justify-content: space-around` to distribute the children wi
|
||||
<span class="snippet__support-note">⚠️ Needs prefixes for full support.</span>
|
||||
|
||||
* https://caniuse.com/#feat=flexbox
|
||||
|
||||
<!-- tags: layout -->
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
### Horizontal and vertical centering
|
||||
### Flexbox centering
|
||||
|
||||
Horizontally and vertically centers a child element within a parent element.
|
||||
Horizontally and vertically centers a child element within a parent element using `flexbox`.
|
||||
|
||||
#### HTML
|
||||
|
||||
```html
|
||||
<div class="horizontal-and-vertical-centering">
|
||||
<div class="child"></div>
|
||||
<div class="flexbox-centering">
|
||||
<div class="child">Centered content.</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### CSS
|
||||
|
||||
```css
|
||||
.horizontal-and-vertical-centering {
|
||||
.flexbox-centering {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
@ -23,13 +23,13 @@ Horizontally and vertically centers a child element within a parent element.
|
||||
#### Demo
|
||||
|
||||
<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 class="snippet-demo__flexbox-centering">
|
||||
<p class="snippet-demo__flexbox-centering__child">Centered content.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.snippet-demo__horizontal-and-vertical-centering {
|
||||
.snippet-demo__flexbox-centering {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
@ -48,3 +48,5 @@ Horizontally and vertically centers a child element within a parent element.
|
||||
<span class="snippet__support-note">⚠️ Needs prefixes for full support.</span>
|
||||
|
||||
* https://caniuse.com/#feat=flexbox
|
||||
|
||||
<!-- tags: layout -->
|
||||
@ -49,3 +49,5 @@ Gives text a gradient color.
|
||||
<span class="snippet__support-note">⚠️ Uses non-standard properties.</span>
|
||||
|
||||
* https://caniuse.com/#feat=text-stroke
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
52
snippets/grid-centering.md
Normal file
52
snippets/grid-centering.md
Normal file
@ -0,0 +1,52 @@
|
||||
### Grid centering
|
||||
|
||||
Horizontally and vertically centers a child element within a parent element using `grid`.
|
||||
|
||||
#### HTML
|
||||
|
||||
```html
|
||||
<div class="grid-centering">
|
||||
<div class="child">Centered content.</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### CSS
|
||||
|
||||
```css
|
||||
.grid-centering {
|
||||
display: grid;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
```
|
||||
|
||||
#### Demo
|
||||
|
||||
<div class="snippet-demo">
|
||||
<div class="snippet-demo__grid-centering">
|
||||
<p class="snippet-demo__grid-centering__child">Centered content.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.snippet-demo__grid-centering {
|
||||
display: grid;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 200px;
|
||||
}
|
||||
</style>
|
||||
|
||||
#### Explanation
|
||||
|
||||
1. `display: grid` enables grid.
|
||||
2. `justify-content: center` centers the child horizontally.
|
||||
3. `align-items: center` centers the child vertically.
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-grid
|
||||
|
||||
<!-- tags: layout -->
|
||||
@ -81,3 +81,5 @@ very sharp and crisp.
|
||||
<hr>
|
||||
|
||||
\*Chrome does not support subpixel values on `border`. Safari does not support subpixel values on `box-shadow`. Firefox supports subpixel values on both.
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -69,7 +69,7 @@ Creates an animated underline effect when the text is hovered over.
|
||||
#### Explanation
|
||||
|
||||
1. `display: inline-block` makes the block `p` an `inline-block` to prevent the underline from
|
||||
spanning the entire parent width rather than just the content (text).
|
||||
spanning the entire parent width rather than just the content (text).
|
||||
2. `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.
|
||||
3. `::after` defines a pseudo-element.
|
||||
4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
|
||||
@ -77,11 +77,11 @@ spanning the entire parent width rather than just the content (text).
|
||||
6. `transform: scaleX(0)` initially scales the pseudo element to 0 so it has no width and is not visible.
|
||||
7. `bottom: 0` and `left: 0` position it to the bottom left of the block.
|
||||
8. `transition: transform 0.25s ease-out` means changes to `transform` will be transitioned over 0.25 seconds
|
||||
with an `ease-out` timing function.
|
||||
with an `ease-out` timing function.
|
||||
9. `transform-origin: bottom right` means the transform anchor point is positioned at the bottom right of the block.
|
||||
10. `:hover::after` then uses `scaleX(1)` to transition the width to 100%, then changes the `transform-origin`
|
||||
to `bottom left` so that the anchor point is reversed, allowing it transition out in the other direction when
|
||||
hovered off.
|
||||
to `bottom left` so that the anchor point is reversed, allowing it transition out in the other direction when
|
||||
hovered off.
|
||||
|
||||
#### Browser support
|
||||
|
||||
@ -89,3 +89,5 @@ hovered off.
|
||||
|
||||
* https://caniuse.com/#feat=transforms2d
|
||||
* https://caniuse.com/#feat=css-transitions
|
||||
|
||||
<!-- tags: animation -->
|
||||
|
||||
@ -41,7 +41,7 @@ A hover effect where the gradient follows the mouse cursor.
|
||||
height: var(--size);
|
||||
background: radial-gradient(circle closest-side, pink, transparent);
|
||||
transform: translate(-50%, -50%);
|
||||
transition: width .2s ease, height .2s ease;
|
||||
transition: width 0.2s ease, height 0.2s ease;
|
||||
}
|
||||
|
||||
.mouse-cursor-gradient-tracking:hover::before {
|
||||
@ -53,7 +53,7 @@ A hover effect where the gradient follows the mouse cursor.
|
||||
|
||||
```js
|
||||
var btn = document.querySelector('.mouse-cursor-gradient-tracking')
|
||||
btn.onmousemove = function (e) {
|
||||
btn.onmousemove = function(e) {
|
||||
var x = e.pageX - btn.offsetLeft
|
||||
var y = e.pageY - btn.offsetTop
|
||||
btn.style.setProperty('--x', x + 'px')
|
||||
@ -131,7 +131,10 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop
|
||||
```
|
||||
|
||||
#### Browser support
|
||||
|
||||
<div class="snippet__requires-javascript">Requires JavaScript</div>
|
||||
<span class="snippet__support-note">⚠️ Requires JavaScript.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-variables
|
||||
|
||||
<!-- tags: visual, interactivity -->
|
||||
|
||||
@ -22,16 +22,19 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 300px;
|
||||
width: 240px;
|
||||
height: 25px;
|
||||
background: linear-gradient(rgba(255, 255, 255, 0.001), white); /* transparent keyword is broken in Safari */
|
||||
background: linear-gradient(
|
||||
rgba(255, 255, 255, 0.001),
|
||||
white
|
||||
); /* transparent keyword is broken in Safari */
|
||||
pointer-events: none;
|
||||
}
|
||||
.overflow-scroll-gradient__scroller {
|
||||
overflow-y: scroll;
|
||||
background: white;
|
||||
width: 300px;
|
||||
height: 250px;
|
||||
width: 240px;
|
||||
height: 200px;
|
||||
padding: 15px 0;
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
@ -56,7 +59,7 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
|
||||
content: '';
|
||||
background: linear-gradient(rgba(255, 255, 255, 0.001), white);
|
||||
position: absolute;
|
||||
width: 300px;
|
||||
width: 240px;
|
||||
height: 25px;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
@ -64,8 +67,8 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
|
||||
.snippet-demo__overflow-scroll-gradient__scroller {
|
||||
overflow-y: scroll;
|
||||
background: white;
|
||||
width: 300px;
|
||||
height: 250px;
|
||||
width: 240px;
|
||||
height: 200px;
|
||||
padding: 15px 0;
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
@ -73,7 +76,7 @@ Adds a fading gradient to an overflowing element to better indicate there is mor
|
||||
</style>
|
||||
|
||||
<script>
|
||||
document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').innerHTML = 'content '.repeat(200)
|
||||
document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').innerHTML = 'content '.repeat(100)
|
||||
</script>
|
||||
|
||||
#### Explanation
|
||||
@ -81,10 +84,10 @@ document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').inne
|
||||
1. `position: relative` on the parent establishes a Cartesian positioning context for pseudo-elements.
|
||||
2. `::after` defines a pseudo element.
|
||||
3. `background-image: linear-gradient(...)` adds a linear gradient that fades from transparent to white
|
||||
(top to bottom).
|
||||
(top to bottom).
|
||||
4. `position: absolute` takes the pseudo element out of the flow of the document and positions it in relation to the parent.
|
||||
5. `width: 300px` matches the size of the scrolling element (which is a child of the parent that has
|
||||
the pseudo element).
|
||||
5. `width: 240px` matches the size of the scrolling element (which is a child of the parent that has
|
||||
the pseudo element).
|
||||
6. `height: 25px` is the height of the fading gradient pseudo-element, which should be kept relatively small.
|
||||
7. `bottom: 0` positions the pseudo-element at the bottom of the parent.
|
||||
8. `pointer-events: none` specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.
|
||||
@ -94,3 +97,5 @@ document.querySelector('.snippet-demo__overflow-scroll-gradient__scroller').inne
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-gradients
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -75,3 +75,5 @@ Reveals an interactive popout menu on hover.
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
<!-- tags: interactivity -->
|
||||
|
||||
@ -16,10 +16,7 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
|
||||
font-family: Arial, sans-serif;
|
||||
display: inline;
|
||||
font-size: 18px;
|
||||
text-shadow: 1px 1px 0 #f5f6f9,
|
||||
-1px 1px 0 #f5f6f9,
|
||||
-1px -1px 0 #f5f6f9,
|
||||
1px -1px 0 #f5f6f9;
|
||||
text-shadow: 1px 1px 0 #f5f6f9, -1px 1px 0 #f5f6f9, -1px -1px 0 #f5f6f9, 1px -1px 0 #f5f6f9;
|
||||
background-image: linear-gradient(90deg, currentColor 100%, transparent 100%);
|
||||
background-position: 0 0.98em;
|
||||
background-repeat: repeat-x;
|
||||
@ -70,13 +67,13 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
|
||||
#### Explanation
|
||||
|
||||
1. `text-shadow: ...` 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 `px` size.
|
||||
has a "thick" shadow that covers the line where descenders clip it. Use a color
|
||||
that matches the background. For a larger font, use a larger `px` size.
|
||||
2. `background-image: linear-gradient(...)` creates a 90deg gradient with the current
|
||||
text color (`currentColor`).
|
||||
text color (`currentColor`).
|
||||
3. The `background-*` properties size the gradient as 1x1px at the bottom and repeats it along the x-axis.
|
||||
4. The `::selection` pseudo selector ensures the text shadow does not interfere with text
|
||||
selection.
|
||||
selection.
|
||||
|
||||
#### Browser support
|
||||
|
||||
@ -84,3 +81,5 @@ Natively implemented as `text-decoration-skip-ink: auto` but it has less control
|
||||
|
||||
* https://caniuse.com/#feat=css-textshadow
|
||||
* https://caniuse.com/#feat=css-gradients
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
47
snippets/reset-all-styles.md
Normal file
47
snippets/reset-all-styles.md
Normal file
@ -0,0 +1,47 @@
|
||||
### Reset all styles
|
||||
|
||||
Resets all styles to default values with one property. This will not affect `direction` and `unicode-bidi` properties.
|
||||
|
||||
#### HTML
|
||||
|
||||
```html
|
||||
<div class="reset-all-styles">
|
||||
<h4>Title</h4>
|
||||
<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>
|
||||
```
|
||||
|
||||
#### CSS
|
||||
|
||||
```css
|
||||
.reset-all-styles {
|
||||
all: initial;
|
||||
}
|
||||
```
|
||||
|
||||
#### Demo
|
||||
|
||||
<div class="snippet-demo">
|
||||
<div class="snippet-demo__reset-all-styles">
|
||||
<h3>Title</h3>
|
||||
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.snippet-demo__reset-all-styles {
|
||||
all: initial;
|
||||
}
|
||||
</style>
|
||||
|
||||
#### Explanation
|
||||
|
||||
The `all` property allows you to reset all styles (inherited or not) to default values.
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">⚠️ MS Edge status is under consideration.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-all
|
||||
|
||||
<!-- tags: visual -->
|
||||
@ -14,6 +14,7 @@ Uses an SVG shape to separate two different blocks to create more a interesting
|
||||
.shape-separator {
|
||||
position: relative;
|
||||
height: 48px;
|
||||
background: #333;
|
||||
}
|
||||
.shape-separator::after {
|
||||
content: '';
|
||||
@ -64,3 +65,5 @@ Uses an SVG shape to separate two different blocks to create more a interesting
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=svg
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
74
snippets/sibling-fade.md
Normal file
74
snippets/sibling-fade.md
Normal file
@ -0,0 +1,74 @@
|
||||
### Sibling fade
|
||||
|
||||
Fades out the siblings of a hovered item.
|
||||
|
||||
#### HTML
|
||||
|
||||
```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>
|
||||
</div>
|
||||
```
|
||||
|
||||
#### CSS
|
||||
|
||||
```css
|
||||
span {
|
||||
padding: 0 1rem;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.sibling-fade:hover span:not(:hover) {
|
||||
opacity: 0.5;
|
||||
}
|
||||
```
|
||||
|
||||
#### Demo
|
||||
|
||||
<div class="snippet-demo">
|
||||
<nav class="snippet-demo__sibling-fade">
|
||||
<span>Item 1</span>
|
||||
<span>Item 2</span>
|
||||
<span>Item 3</span>
|
||||
<span>Item 4</span>
|
||||
<span>Item 5</span>
|
||||
<span>Item 6</span>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.snippet-demo__sibling-fade {
|
||||
cursor: default;
|
||||
line-height: 2;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.snippet-demo__sibling-fade span {
|
||||
padding: 1rem;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.snippet-demo__sibling-fade:hover span:not(:hover) {
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
#### Explanation
|
||||
|
||||
1. `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.2 seconds.
|
||||
2. `.sibling-fade:hover span:not(:hover)` specifies that when the parent is hovered, select any `span` children
|
||||
that are not currently being hovered and change their opacity to `0.5`.
|
||||
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
* https://caniuse.com/#feat=css-sel3
|
||||
* https://caniuse.com/#feat=css-transitions
|
||||
|
||||
<!-- tags: interactivity -->
|
||||
@ -12,7 +12,8 @@ Uses the native font of the operating system to get close to a native app feel.
|
||||
|
||||
```css
|
||||
.system-font-stack {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu,
|
||||
Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
}
|
||||
```
|
||||
|
||||
@ -46,3 +47,5 @@ falls back to the next if it cannot find the font (on the system or defined in C
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -89,3 +89,5 @@ Experiment with the `px` values to change the proportion of the triangle.
|
||||
#### Browser support
|
||||
|
||||
<span class="snippet__support-note">✅ No caveats.</span>
|
||||
|
||||
<!-- tags: visual -->
|
||||
|
||||
@ -51,3 +51,5 @@ If the text is longer than one line, it will be truncated and end with an ellips
|
||||
<span class="snippet__support-note">⚠️ Only works for single line elements.</span>
|
||||
|
||||
* https://caniuse.com/#feat=text-overflow
|
||||
|
||||
<!-- tags: layout -->
|
||||
|
||||
Reference in New Issue
Block a user