css 如何防止此图像在悬停时抖动/振动

0lvr5msh  于 2023-03-20  发布在  其他
关注(0)|答案(1)|浏览(112)

我想增加容器的宽度和高度,同时图像不受影响。换句话说,我想让图像在悬停在容器上时停止抖动。我尝试过格式化宽度、定位和对象适合属性,但似乎没有任何效果。这太令人沮丧了,我需要帮助。
先谢谢你。
下面是HTML代码:

@font-face {
  font-family: Hanyi;
  src: url(/HanyiSentyBrushSong.ttf);
}

 :root {
  --my-font: Hanyi;
}

body {
  height: 100vh;
  margin: 0;
  background-color: #000000;
}

.image-container {
  width: 300px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: none;
  border-radius: 50px;
  height: 400px;
  background-color: #262626;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all .6s ease-in-out;
  display: inline-flex;
  align-content: center;
}

.image-container:hover {
  width: 350px;
  height: 450px;
  transform-origin: center;
  cursor: pointer;
}

img {
  object-fit: cover;
  width: 300px;
  height: auto;
  border-radius: 50px 50px 0px 0px;
}
<div class="image-container">
  <img src="/Ny mapp/destiny-ayodele-0xdWoqxoF_Q-unsplash.jpg" alt="image">
</div>
jum4pzuy

jum4pzuy1#

你所要做的就是

.image-container:hover {
    width: 350px;
    height: 450px;
    transform-origin: center;
    cursor: pointer;
}  

/* Comment These Out */
.image-container {
  border-radius: 50px;
  background-color: #262626;
  transition: all .6s ease-in-out;
}

并加上

.image-container::before {
  position: absolute;
  content: '';
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  border-radius: 50px;
  background-color: #262626;
  transition: all .6s ease-in-out;
  transform: scale(1);
  z-index: -1;
}

.image-container:hover::before {
  transform: scale(1.1);
}

演示

一个二个一个一个

相关问题