2.6 KiB
2.6 KiB
Hover Shadow Box Animation
Creates a shadow box around the text whern it is hovered.
HTML
<h4 class = "hover-shadow-box-animation"> Box it! </h4>
CSS
.hover-shadow-box-animation{
display: inline-block;
vertical-align: middle;
-webkit-transform:perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px transparent;
margin: 10px;
-webkit-transition-duration : 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: box-shadow, transform;
transition-property: box-shadow, transform;
}
.hover-shadow-box-animation:hover, .hover-shadow-box-animation:focus, .hover-shadow-box-animation:active{
box-shadow: 1px 10px 10px -10px rgba(0,0,24,0.5);
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
Demo
Box it!
Explanation
display: inline-blockfor giving width and length forh4element thus making it as aninline-block.- setting the
transform: perspective(1px)for giving element a 3-D space by affecting the distance between the Z plane and the user andtranslate(0)for repositioningh4element along z-axis in 3-D Space. box-shadow:for setting up the box.transparentto make box transparent 5.transition-propertyfor enabling both box-shadow and transform:hoverto activate whole css when hovering is done tillactive.transform: scale(1.2)for changing the scale to 1.2. Now text looks for 1.2 times magnified with shadow Box Effect
Browser Support
✅ No caveats.