diff --git a/README.md b/README.md
index b1be17ca9..6da6c51e2 100644
--- a/README.md
+++ b/README.md
@@ -21,95 +21,97 @@ See CONTRIBUTING.md for the snippet template.
- [30 Seconds of Interviews](https://30secondsofinterviews.org/)
- [30 Seconds of React](https://github.com/30-seconds/30-seconds-of-react)
-### Animation
+### Animation
View contents
-- [`Bouncing loader`](#bouncing-loader)
-- [`Button border animation`](#button-border-animation)
-- [`Donut spinner`](#donut-spinner)
-- [`Easing variables`](#easing-variables)
-- [`Height transition`](#height-transition)
-- [`Hover shadow box animation`](#hover-shadow-box-animation)
-- [`Hover underline animation`](#hover-underline-animation)
+* [`Bouncing loader`](#bouncing-loader)
+* [`Button border animation`](#button-border-animation)
+* [`Donut spinner`](#donut-spinner)
+* [`Easing variables`](#easing-variables)
+* [`Height transition`](#height-transition)
+* [`Hover shadow box animation`](#hover-shadow-box-animation)
+* [`Hover underline animation`](#hover-underline-animation)
-### Interactivity
+### Interactivity
View contents
-- [`Disable selection`](#disable-selection)
-- [`Popout menu`](#popout-menu)
-- [`Sibling fade`](#sibling-fade)
+* [`Disable selection`](#disable-selection)
+* [`Popout menu`](#popout-menu)
+* [`Sibling fade`](#sibling-fade)
-### Layout
+### Layout
View contents
-- [`Box-sizing reset`](#box-sizing-reset)
-- [`Clearfix`](#clearfix)
-- [`Constant width to height ratio`](#constant-width-to-height-ratio)
-- [`Display table centering`](#display-table-centering)
-- [`Evenly distributed children`](#evenly-distributed-children)
-- [`Fit image in container`](#fit-image-in-container)
-- [`Flexbox centering`](#flexbox-centering)
-- [`Ghost trick`](#ghost-trick)
-- [`Grid centering`](#grid-centering)
-- [`Last item with remaining available height`](#last-item-with-remaining-available-height)
-- [`Offscreen`](#offscreen)
-- [`Transform centering`](#transform-centering)
-- [`Truncate text multiline`](#truncate-text-multiline)
-- [`Truncate text`](#truncate-text)
+* [`Box-sizing reset`](#box-sizing-reset)
+* [`Clearfix`](#clearfix)
+* [`Constant width to height ratio`](#constant-width-to-height-ratio)
+* [`Display table centering`](#display-table-centering)
+* [`Evenly distributed children`](#evenly-distributed-children)
+* [`Fit image in container`](#fit-image-in-container)
+* [`Flexbox centering`](#flexbox-centering)
+* [`Ghost trick`](#ghost-trick)
+* [`Grid centering`](#grid-centering)
+* [`Last item with remaining available height`](#last-item-with-remaining-available-height)
+* [`Offscreen`](#offscreen)
+* [`Transform centering`](#transform-centering)
+* [`Truncate text multiline`](#truncate-text-multiline)
+* [`Truncate text`](#truncate-text)
-### Other
+### Other
View contents
-- [`Calc()`](#calc)
-- [`Custom variables`](#custom-variables)
+* [`Calc()`](#calc)
+* [`Custom variables`](#custom-variables)
-### Visual
+### Visual
View contents
-- [`Circle`](#circle)
-- [`Counter`](#counter)
-- [`Custom scrollbar`](#custom-scrollbar)
-- [`Custom text selection`](#custom-text-selection)
-- [`Dynamic shadow`](#dynamic-shadow)
-- [`Etched text`](#etched-text)
-- [`Focus Within`](#focus-within)
-- [`Fullscreen`](#fullscreen)
-- [`Gradient text`](#gradient-text)
-- [`Hairline border`](#hairline-border)
-- [`Mouse cursor gradient tracking`](#mouse-cursor-gradient-tracking)
-- [`:not selector`](#not-selector)
-- [`Overflow scroll gradient`](#overflow-scroll-gradient)
-- [`Pretty text underline`](#pretty-text-underline)
-- [`Reset all styles`](#reset-all-styles)
-- [`Shape separator`](#shape-separator)
-- [`System font stack`](#system-font-stack)
-- [`Toggle switch`](#toggle-switch)
-- [`Triangle`](#triangle)
-- [`Zebra striped list`](#zebra-striped-list)
+* [`Circle`](#circle)
+* [`Counter`](#counter)
+* [`Custom scrollbar`](#custom-scrollbar)
+* [`Custom text selection`](#custom-text-selection)
+* [`Dynamic shadow`](#dynamic-shadow)
+* [`Etched text`](#etched-text)
+* [`Focus Within`](#focus-within)
+* [`Fullscreen`](#fullscreen)
+* [`Gradient text`](#gradient-text)
+* [`Hairline border`](#hairline-border)
+* [`Mouse cursor gradient tracking`](#mouse-cursor-gradient-tracking)
+* [`:not selector`](#not-selector)
+* [`Overflow scroll gradient`](#overflow-scroll-gradient)
+* [`Pretty text underline`](#pretty-text-underline)
+* [`Reset all styles`](#reset-all-styles)
+* [`Shape separator`](#shape-separator)
+* [`System font stack`](#system-font-stack)
+* [`Toggle switch`](#toggle-switch)
+* [`Triangle`](#triangle)
+* [`Zebra striped list`](#zebra-striped-list)
+
---
-## Animation
+## Animation
+
### Bouncing loader
@@ -150,8 +152,10 @@ Creates a bouncing loader animation.
}
```
+
#### 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: translate3d()`. Using a single axis translation on `transform: translate3d()` improves the performance of the animation.
@@ -162,6 +166,7 @@ Note: `1rem` is usually `16px`.
6. `nth-child(n)` targets the element which is the nth child of its parent.
7. `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
100.0%
@@ -216,10 +221,13 @@ Creates a border animation on hover.
}
```
+
#### Explanation
+
- Use the `:before` and `:after` pseduo-elements as borders that animate on hover.
+
#### Browser support
100.0%
@@ -254,10 +262,13 @@ Creates a donut spinner that can be used to indicate the loading of content.
}
```
+
#### Explanation
+
- Use a semi-transparent `border` for the whole element, except one side that will serve as the loading indicator for the donut. Use `animation` to rotate the element.
+
#### Browser support
100.0%
@@ -320,11 +331,14 @@ powerful than the built-in `ease`, `ease-in`, `ease-out` and `ease-in-out`.
}
```
+
#### Explanation
+
- The variables are defined globally within the `:root` CSS pseudo-class which matches the root element of a tree representing the document.
- In HTML, `:root` represents the `` element and is identical to the selector `html`, except that its specificity is higher.
+
#### Browser support
96.5%
@@ -362,8 +376,10 @@ var height = el.scrollHeight
el.style.setProperty('--max-height', height + 'px')
```
+
#### Explanation
+
1. `transition: max-height: 0.5s cubic-bezier(...)` specifies that changes to `max-height` should be transitioned over 0.5 seconds, using an `ease-out-quint` timing function.
2. `overflow: hidden` prevents the contents of the hidden element from overflowing its container.
3. `max-height: 0` specifies that the element has no height initially.
@@ -374,6 +390,7 @@ el.style.setProperty('--max-height', height + 'px')
1. `el.scrollHeight` is the height of the element including overflow, which will change dynamically based on the content of the element.
2. `el.style.setProperty(...)` sets the `--max-height` CSS variable which is used to specify the `max-height` of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.
+
#### Browser support
96.5%
@@ -415,8 +432,10 @@ Creates a shadow box around the text when it is hovered.
}
```
+
#### Explanation
+
1. `display: inline-block` to set width and length for `p` element thus making it an `inline-block`.
2. Set `transform: perspective(1px)` to give element a 3D space by affecting the distance between the Z plane and the user and `translate(0)` to reposition the `p` element along z-axis in 3D space.
3. `box-shadow:` to set up the box.
@@ -425,6 +444,7 @@ Creates a shadow box around the text when it is hovered.
6. `:hover` to activate whole css when hovering is done until `active`.
7. `transform: scale(1.2)` to change the scale, magnifying the text.
+
#### Browser support
100.0%
@@ -468,8 +488,10 @@ 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).
2. `position: relative` on the element establishes a Cartesian positioning context for pseudo-elements.
3. `::after` defines a pseudo-element.
@@ -481,6 +503,7 @@ Creates an animated underline effect when the text is hovered over.
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.
+
#### Browser support
100.0%
@@ -492,7 +515,8 @@ Creates an animated underline effect when the text is hovered over.
---
-## Interactivity
+## Interactivity
+
### Disable selection
@@ -509,10 +533,13 @@ Makes the content unselectable.
}
```
+
#### Explanation
+
- `user-select: none` specifies that the text cannot be selected.
+
#### Browser support
97.5%
@@ -555,8 +582,10 @@ Reveals an interactive popout menu on hover and focus.
}
```
+
#### Explanation
+
1. `position: relative` on the reference parent establishes a Cartesian positioning context for its child.
2. `position: absolute` takes the popout menu out of the flow of the document and positions it in relation to the parent.
3. `left: 100%` moves the the popout menu 100% of its parent's width from the left.
@@ -565,6 +594,7 @@ Reveals an interactive popout menu on hover and focus.
6. `.reference:focus > .popout-menu` means that when `.reference` is focused, the popout would be shown.
7. `.reference:focus-within > .popout-menu` ensures that the popout is shown when the focus is _within_ the reference.
+
#### Browser support
100.0%
@@ -593,11 +623,14 @@ span {
}
```
+
#### 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
100.0%
@@ -609,7 +642,8 @@ span {
---
-## Layout
+## Layout
+
### Box-sizing reset
@@ -643,11 +677,14 @@ html {
}
```
+
#### Explanation
+
1. `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.
2. `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.
+
#### Browser support
100.0%
@@ -682,12 +719,15 @@ Ensures that an element self-clears its children.
}
```
+
#### Explanation
+
1. `.clearfix::after` defines a pseudo-element.
2. `content: ''` allows the pseudo-element to affect layout.
3. `clear: both` indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.
+
#### Browser support
100.0%
@@ -722,11 +762,14 @@ Given an element of variable width, it will ensure its height remains proportion
}
```
+
#### Explanation
+
- `padding-top` on the `::before` pseudo-element causes the height of the element to equal a percentage of its width. `100%` therefore means the element's height will always be `100%` of the width, creating a responsive square.
- This method also allows content to be placed inside the element normally.
+
#### Browser support
100.0%
@@ -763,8 +806,10 @@ Vertically and horizontally centers a child element within its parent element us
}
```
+
#### Explanation
+
1. `display: table` on '.center' allows the element to behave like a `
` HTML element.
2. 100% height and width on '.center' allows the element to fill the available space within its parent element.
3. `display: table-cell` on '.center > span' allows the element to behave like an
HTML element.
@@ -773,6 +818,7 @@ Vertically and horizontally centers a child element within its parent element us
- The outer parent ('.container' in this case) must have a fixed height and width.
+
#### Browser support
100.0%
@@ -800,13 +846,16 @@ Evenly distributes child elements within a parent element.
}
```
+
#### Explanation
+
1. `display: flex` enables flexbox.
2. `justify-content: space-between` evenly distributes child elements horizontally. The first item is positioned at the left edge, while the last item is positioned at the right edge.
- Alternatively, use `justify-content: space-around` to distribute the children with space around them, rather than between them.
+
#### Browser support
100.0%
@@ -845,12 +894,15 @@ Changes the fit and position of an image within its container while preserving i
}
```
+
#### Explanation
+
- `object-fit: contain` fits the entire image within the container while preserving its aspect ratio.
- `object-fit: cover` fills the container with the image while preserving its aspect ratio.
- `object-position: [x] [y]` positions the image within the container.
+
#### Browser support
99.5%
@@ -876,12 +928,15 @@ Horizontally and vertically centers a child element within a parent element usin
}
```
+
#### Explanation
+
1. `display: flex` enables flexbox.
2. `justify-content: center` centers the child horizontally.
3. `align-items: center` centers the child vertically.
+
#### Browser support
100.0%
@@ -921,10 +976,13 @@ p {
}
```
+
#### Explanation
+
- Use the style of a `:before` pseudo-element to vertically align inline elements without changing their `position` property.
+
#### Browser support
100.0%
@@ -950,12 +1008,15 @@ Horizontally and vertically centers a child element within a parent element usin
}
```
+
#### Explanation
+
1. `display: grid` enables grid.
2. `justify-content: center` centers the child horizontally.
3. `align-items: center` centers the child vertically.
+
#### Browser support
97.3%
@@ -995,8 +1056,10 @@ body {
}
```
+
#### Explanation
+
1. `height: 100%` set the height of container as viewport height.
2. `display: flex` enables flexbox.
3. `flex-direction: column` set the direction of flex items' order from top to down.
@@ -1004,6 +1067,7 @@ body {
- The parent must have a viewport height. `flex-grow: 1` could be applied to the first or second element, which will have all available space.
+
#### Browser support
100.0%
@@ -1037,8 +1101,10 @@ A bulletproof way to completely hide an element visually and positionally in the
}
```
+
#### Explanation
+
1. Remove all borders.
2. Use `clip` to indicate that no part of the element should be shown.
3. Make the height and width of the element 1px.
@@ -1047,6 +1113,7 @@ A bulletproof way to completely hide an element visually and positionally in the
6. Remove all padding.
7. Position the element absolutely so that it does not take up space in the DOM.
+
#### Browser support
100.0%
@@ -1082,14 +1149,17 @@ Vertically and horizontally centers a child element within its parent element us
}
```
+
#### Explanation
+
1. `position: absolute` on the child element allows it to be positioned based on its containing block.
2. `left: 50%` and `top: 50%` offsets the child 50% from the left and top edge of its containing block.
3. `transform: translate(-50%, -50%)` allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
- Note: that the fixed height and width on parent element is for the demo only.
+
#### Browser support
100.0%
@@ -1134,14 +1204,17 @@ If the text is longer than one line, it will be truncated for `n` lines and end
}
```
+
#### Explanation
+
1. `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).
2. `width: 400px` ensures the element has a dimension.
3. `height: 109.2px` calculated value for height, it equals `font-size * line-height * numberOfLines` (in this case `26 * 1.4 * 3 = 109.2`)
4. `height: 36.4px` calculated value for gradient container, it equals `font-size * line-height` (in this case `26 * 1.4 = 36.4`)
5. `background: linear-gradient(to right, rgba(0, 0, 0, 0), #f5f6f9 50%)` gradient from `transparent` to `#f5f6f9`
+
#### Browser support
100.0%
@@ -1167,13 +1240,16 @@ If the text is longer than one line, it will be truncated and end with an ellips
}
```
+
#### Explanation
+
1. `overflow: hidden` prevents the text from overflowing its dimensions (for a block, 100% width and auto height).
2. `white-space: nowrap` prevents the text from exceeding one line in height.
3. `text-overflow: ellipsis` makes it so that if the text exceeds its dimensions, it will end with an ellipsis.
4. `width: 200px;` ensures the element has a dimension, to know when to get ellipsis
+
#### Browser support
100.0%
@@ -1186,7 +1262,8 @@ If the text is longer than one line, it will be truncated and end with an ellips
---
-## Other
+## Other
+
### Calc()
@@ -1204,13 +1281,16 @@ The function calc() allows to define CSS values with the use of mathematical exp
}
```
+
#### Explanation
+
1. It allows addition, subtraction, multiplication and division.
2. Can use different units (pixel and percent together, for example) for each value in your expression.
3. It is permitted to nest calc() functions.
4. It can be used in any property that ``, ``, ``, `