CSS动画异常求助:圆形缩放与注册表单显示时序不符
问题排查与修复方案
核心错误:CSS动画属性拼写错误
代码中将动画时长属性误写为方向属性,导致动画逻辑完全混乱:
.circle和.register-form-container中的animation-direction: .7s是错误写法,该属性用于控制动画播放方向(如normal/reverse),正确的动画时长属性是animation-duration。- 这个错误会让浏览器无法识别动画时长,最终导致表单出现异常延迟。
额外问题修复
- 表单容器背景色错误:
.register-form-container中background: #FFFFF少了一个F,应为background: #FFFFFF(或直接写white),否则背景色显示异常。 - HTML类名与标签拼写错误:所有
form-flield应为form-field,buttton标签多写了一个t,这些错误会导致样式失效或标签功能异常。
修复后的完整代码
CSS 代码
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Roboto', sans-serif; } input { height: 45px; width: 100%; color: #385983; font-size: 14px; line-height: 16px; border: 2px solid #E9F2FF; border-radius: 5px; padding-left: 25px; } input:focus { outline: none; border: 2px solid #C1D9FD; } main { background: #F1F5FE; height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; } .circle { position: absolute; z-index: 1; width: 2534px; height: 2534px; border-radius: 50%; background: #F7FAFF; box-shadow: 0px 4px 70px 6px rgba(217, 229, 255, 0.25); animation-name: fadeCircle; animation-duration: .7s; /* 修正属性名 */ animation-timing-function: ease-in-out; animation-delay: .5s; animation-iteration-count: 1; animation-fill-mode: forwards; } @keyframes fadeCircle { 0% { width: 2534px; height: 2534px; } 100% { width: 534px; height: 534px; } } .register-form-container { opacity: 0; position: relative; z-index: 2; max-width: 415px; width: 100%; background: #FFFFFF; /* 修正背景色 */ box-shadow: 0px 6px 50px rgba(217, 229, 225, 0.7); border-radius: 20px; padding-left: 30px; padding-right: 30px; padding-top: 38px; padding-bottom: 38px; animation-name: fadeForm; animation-duration: .7s; /* 修正属性名 */ animation-timing-function: ease-in-out; animation-delay: 1.2s; /* 调整延迟让动画更连贯 */ animation-iteration-count: 1; animation-fill-mode: forwards; } @keyframes fadeForm { 0% { opacity: 0; } 100% { opacity: 1; } } .form-title { color: #30507D; font-weight: 500; font-size: 20px; line-height: 23px; margin-bottom: 38px; } .form-field { margin-bottom: 13px; } .button { font-weight: bold; font-size: 14px; display: block; height: 45px; background: #247FFF; border-radius: 5px; color: #fff; text-transform: uppercase; text-align: center; line-height: 45px; cursor: pointer; } .button:hover { background-color: #0D6CF2; } a.button { text-decoration: none; } .button-google { color: #C6CFDC; background: #F2F6FF; } .button-google:hover { background: #E2E6F0; color: #fff } .divider { font-weight: 500; font-size: 12px; line-height: 14px; color: #405D87; text-align: center; padding-top: 25px; padding-bottom: 25px; }
HTML 代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet"> <link rel="stylesheet" href="css/style.css"> <title>book.py</title> </head> <body> <main> <div class="circle"></div> <div class="register-form-container"> <h1 class="form-title"> Регистрация </h1> <div class="form-field"> <div class="form-field"> <input type="text" placeholder="Имя"> </div> <div class="form-field"> <input type="text" placeholder="Почта"> </div> <div class="form-field"> <input type="text" placeholder="Пароль"> </div> <div class="form-field"> <input type="text" placeholder="Подтвердить Пароль"> </div> </div> <div class="form-buttons"> <button class="button">Регистрация</button> <div class="divider">или</div> <a href="#" class="button button-google">Google</a> </div> </div> </main> </body> </html>
优化说明
- 简化了
@keyframes关键帧,只保留起始和结束状态,浏览器会自动补间,效果一致且代码更简洁。 - 调整表单动画延迟为1.2s,让圆形缩小动画接近完成时开始表单淡入,实现连贯的预期效果。
内容的提问来源于stack exchange,提问作者bulka111
相关产品推荐
相关产品推荐

