Bouncing loader
Creates a bouncing loader animation.
HTML
<div class="bouncing-loader">
+ 30 Seconds of CSS
30 Seconds of CSS
A curated collection of useful CSS snippets you can understand in 30 seconds or less.
Bouncing loader
Creates a bouncing loader animation.
HTML
<div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
@@ -437,7 +437,7 @@ p {
JavaScript
var el = document.querySelector('.el')
var height = el.scrollHeight
el.style.setProperty('--max-height', height + 'px')
-
Demo
Hover me to see a height transition. content Explanation
CSS
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. overflow: hidden prevents the contents of the hidden element from overflowing its container. max-height: 0 specifies that the element has no height initially. .target:hover > .el specifies that when the parent is hovered over, target a child .el within it and use the --max-height variable which was defined by JavaScript.
JavaScript
el.scrollHeight is the height of the element including overflow, which will change dynamically based on the content of the element. 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
91.6% Requires JavaScript ⚠️ Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height. Hover Shadow Box Animation
Creates a shadow box around the text whern it is hovered.
HTML
<p class="hover-shadow-box-animation">Box it!</p>
+
Demo
Hover me to see a height transition. content Explanation
CSS
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. overflow: hidden prevents the contents of the hidden element from overflowing its container. max-height: 0 specifies that the element has no height initially. .target:hover > .el specifies that when the parent is hovered over, target a child .el within it and use the --max-height variable which was defined by JavaScript.
JavaScript
el.scrollHeight is the height of the element including overflow, which will change dynamically based on the content of the element. 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
91.6% Requires JavaScript ⚠️ Causes reflow on each animation frame, which will be laggy if there are a large number of elements beneath the element that is transitioning in height. Hover shadow box animation
Creates a shadow box around the text when it is hovered.
HTML
<p class="hover-shadow-box-animation">Box it!</p>
CSS
.hover-shadow-box-animation {
display: inline-block;
vertical-align: middle;
diff --git a/index.html b/index.html
index 458fc7522..77f3bd00e 100644
--- a/index.html
+++ b/index.html
@@ -38,7 +38,7 @@
- Hover Shadow Box Animation
+ Hover shadow box animation
Creates a shadow box around the text when it is hovered.
HTML
<p class="hover-shadow-box-animation">Box it!</p>