This is a simple way to achieve the effect:

  1. 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);
}
  1. 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>
  1. 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>
CSS Hover Effect: Make a Div Jump on Mouseover

原文地址: http://www.cveoy.top/t/topic/jM1i 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录