You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CSS过渡时卡片文本抖动模糊问题求助(附代码)

解决卡片Hover过渡时文本抖动、模糊的问题

问题根源

你的代码里存在两个核心问题导致了抖动和模糊:

  • 父容器.servizio-card hover时已经做了scale(1.1),内部的.servizio-card-content-container又叠加了一次scale(1.1),双重缩放让内容被过度放大,出现模糊
  • 缩放过程中浏览器没有足够的渲染优化,导致像素对齐偏差,引发抖动

修复方案

  1. 移除双重缩放:删掉.servizio-card:hover .servizio-card-content-container里的transform: scale(1.1),父容器的缩放已经会带动内部元素,不需要重复缩放
  2. 添加渲染优化属性:给.servizio-card加上transform-style: preserve-3d、backface-visibility: hidden和will-change: transform,帮助浏览器提前准备渲染资源,减少抖动
  3. 修正opacity值:按钮的opacity: 100是错误写法,改成opacity: 1(opacity取值范围是0-1)
  4. 明确过渡属性:把通用的transition: 1s改成指定属性的过渡,避免不必要的性能消耗

修改后的完整代码

CSS

.card-wrapper {
  position: relative;
  width: 300px;
  display: inline-block;

  &::after {
    content: '';
    display: block;
    padding-top: 100%;
  }
}

.servizio-card {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  background-color: #fff;
  background-clip: border-box;
  border: 1px solid rgba(0, 0, 0, 0.125);
  border-radius: 10%;

  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;

  margin-bottom: 1.5rem;

  animation-fill-mode: backwards;
  animation-duration: 1s;
  animation-timing-function: ease-in-out;
  /* 明确过渡属性,添加渲染优化 */
  transition: transform 1s ease-in-out;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  will-change: transform;
  z-index: 10;
  
  &:hover {
    transform: scale(1.1);
    
    .servizio-card-content-container {
      height: 60%;
      /* 移除重复的scale */
    }
    
    .overlay {
      background-color: rgba(0,0,0, 0.35);
    }
    
    .button {
      opacity: 1; /* 修正为正确的opacity值 */
    }
    
    img {
      transform: scale(1.1) rotate(-3deg);
    }
  }
}

.servizio-img {
  transition: transform 1s ease-in-out; /* 明确过渡属性 */
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: -10;
}

.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;

  display: flex;
  flex-direction: column;
  justify-content: flex-end;

  background-color: rgba(0,0,0, 0.5);
  transition: background-color 1s ease-in-out; /* 明确过渡属性 */
  z-index: 2
} 

.servizio-card-content-container {
  height: 40%;
  transition: height 1s ease-in-out; /* 明确过渡属性 */

  display: flex;
  flex-direction: column;
  align-items: center;
}

.servizio-card-title {
  margin-bottom: 5%;
  color: black;
}

.button {
  opacity: 0;
  display: inline-block;

  font-weight: 400;
  line-height: 1.5;
  color: white;

  text-align: center;
  text-decoration: none;
  vertical-align: middle;

  cursor: pointer;
  user-select: none;

  background-color: #0d6efd;
  border: 1px solid #0d6efd;
  padding: 0.375rem 0.75rem;
  border-radius: 0.25rem;

  transition: opacity 1s ease-in-out; /* 明确过渡属性 */
}

HTML

<div class="card-wrapper">
  <div class="servizio-card box-shadow">
    <img
      src="https://i1.wp.com/potafiori.com/wp-content/uploads/2020/04/placeholder.png?ssl=1"
      class="servizio-img"
      alt="placeholder_img"
    />
    <div class="overlay">
      <div class="servizio-card-content-container">
        <h5
          class="servizio-card-title"
          style="
            font-size: 18px;
            font-weight: bold;
            min-height: 42px;
          "
        >
          Card
        </h5>
        <a href="#" class="button"
          >Find out more!</a
        >
      </div>
    </div>
  </div>
</div>

内容的提问来源于stack exchange,提问作者Enorrav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 12:01:00