CSS Hover Effect: Make a Div Jump on Mouseover
This is a simple way to achieve the effect:
- Define a hover pseudo-class in CSS to set the div's transform property to translateY(-10px) when the mouse is over the div.
div:hover {
transform: translateY(-10px);
}
- Add a div element in your HTML and style it.
<div class='box'>Hover me!</div>
<style>
.box {
width: 100px;
height: 100px;
background-color: #ccc;
transition: transform 0.3s ease-in-out;
}
</style>
- The div will jump up by 10 pixels when the mouse hovers over it.
Here's the complete code:
<div class='box'>Hover me!</div>
<style>
.box {
width: 100px;
height: 100px;
background-color: #ccc;
transition: transform 0.3s ease-in-out;
}
.box:hover {
transform: translateY(-10px);
}
</style>
原文地址: http://www.cveoy.top/t/topic/jM1i 著作权归作者所有。请勿转载和采集!