Creates a shadow box around the text when it is hovered.
display: inline-block
to set width and length forp
element thus making it aninline-block
.- Set
transform: perspective(1px)
to give element a 3D space by affecting the distance between the Z plane and the user andtranslate(0)
to reposition thep
element along z-axis in 3D space. box-shadow:
to set up the box.transparent
to make box transparent.transition-property
to enable transitions for bothbox-shadow
andtransform
.:hover
to activate whole css when hovering is done untilactive
.transform: scale(1.2)
to change the scale, magnifying the text.
预览
Box it!
HTML
<p class="hover-shadow-box-animation">Box it!</p>
CSS
.hover-shadow-box-animation {
display: inline-block;
vertical-align: middle;
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px transparent;
margin: 10px;
transition-duration: 0.3s;
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);
transform: scale(1.2);
}
翻译自:https://www.30secondsofcode.org/css/s/hover-shadow-box-animation