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

CSS Transition不生效:点击按钮后元素仅显隐无平滑过渡

Fixing Smooth Transition for Your Dynamic Text Elements

Hey there! I see the issue right away—your CSS transition declarations have a syntax error that's preventing the smooth animation from working. Let's break down the problem and fix it step by step.

The Root Cause

Your transition property is written in the wrong order and missing a critical time unit. Right now you have:

transition:2.5 all ease;
transition:2.7 all ease;

The correct syntax for the transition property is:
transition: [property] [duration] [timing-function];
You've placed the duration first, and more importantly, you didn't add the time unit (s for seconds). Browsers can't interpret 2.5 as a duration without a unit, so they ignore the entire transition rule.

Corrected CSS Code

Here's the fixed version of your CSS with proper transition syntax:

.content-container-title { 
  text-align: center; 
  width:40%; 
  transition: all 2.5s ease; /* Fixed order + added 's' unit */
  margin:140px 30% 0 30%; 
  opacity:0; 
} 

.titleShown { opacity:1; } 

.content-container-title h2 { 
  font-family: cuisine; 
  font-size:50px; 
  margin:0; 
  text-shadow: 0 0 5px rgba(0,0,0,1); /* Removed extra unnecessary 0 */
} 

.content-container-text { 
  text-align:center; 
  width:50%; 
  opacity:0; 
  margin:20px 25%; 
  transition: all 2.7s ease; /* Fixed order + added 's' unit */
  overflow:hidden; 
} 

.textShown { opacity: 1; } 

.content-container-text p { 
  margin:0; 
  font-family: cuisine; 
  font-size:24px; 
  opacity: 0.8; 
}

Quick Notes to Ensure It Works

  • I also cleaned up the text-shadow value in your h2 rule—you had an extra 0 (0 0 5px 0 rgba(...)) which isn't necessary for that property's syntax.
  • Your JavaScript logic for adding the classes after a timeout is correct, since you're waiting for the dynamic elements to be inserted into the DOM before triggering the transition. Just keep using that flow to ensure the elements exist when the class is applied.

Once you update the CSS transitions, your .content-container-title and .content-container-text elements will smoothly fade in instead of popping into view.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 10:00:27