上一篇
/* 🎯 精准居中:水平+垂直双飞翼 */ .container { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #ff6b6b, #4ecdc4); } /* 🧩 网格布局:3列等宽+自适应间距 */ .grid-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
/* 🔥 立体阴影:长投影+内发光 */ .box-shadow { box-shadow: 0 20px 40px rgba(0,0,0,0.2), inset 0 0 10px rgba(255,255,255,0.3); border-radius: 20px; background: linear-gradient(145deg, #fff, #f0f0f0); } /* 🌈 渐变边框:双层叠加实现3D效果 */ .gradient-border { border: 3px solid transparent; background-image: linear-gradient(white, white), linear-gradient(to right, #ff6b6b, #4ecdc4); background-origin: border-box; background-clip: padding-box, border-box; }
/* 💫 悬停缩放+阴影增强 */ .card:hover { transform: scale(1.05); box-shadow: 0 30px 60px rgba(0,0,0,0.3); transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); } /* 👆 点击涟漪效果 */ .ripple { position: relative; overflow: hidden; } .ripple::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle, rgba(255,255,255,0.3) 60%, transparent 100%); opacity: 0; transition: opacity 0.5s; } .ripple:active::after { opacity: 1; }
.lazy-section {
content-visibility: auto;
contain-intrinsic-size: 600px; /* 预估高度防抖动 */
}
/* 📜 滚动条预占位:告别布局跳动 */
html {
scrollbar-gutter: stable both-edges;
scrollbar-color: #999 #eee;
}
/* 🎨 主题色集中管理 */ :root { --primary: #3498db; --secondary: #e74c3c; } .button { background: var(--primary); color: white; } /* 🛡️ 样式作用域限定 */ @scope (.card) { h3 { color: var(--primary); } p { color: var(--secondary); } }
/* 📱 移动优先:vw单位+clamp字体 */{ font-size: clamp(18px, 4vw, 24px); padding: 5vw; } /* 🖥️ 桌面端适配:媒体查询+暗黑模式 */ @media (min-width: 1024px) { .grid-box { grid-template-columns: repeat(3, 1fr); } } @media (prefers-color-scheme: dark) { body { background: #1a1a1a; color: #fff; } }
@property --btn-bg { syntax: "<color>"; initial-value: #3498db; inherits: false; } .btn:hover { --btn-bg: hsl(from var(--btn-bg) h s calc(l - 10%)); background: var(--btn-bg); }
.ball { offset-path: path("M0,0 C100,50 200,100 300,0"); animation: move 3s infinite; } @keyframes move { to { offset-distance: 100%; } }
<details class="accordion"> <summary>🔍 点击展开</summary> <p>隐藏内容...</p> </details> <style> details[open] summary ~ * { animation: fadeIn 0.5s; } @keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } } </style>
<div class="magic-box"></div> <style> .magic-box { width: 200px; height: 200px; border-radius: 16px; background: var(--color, #3498db); transition: background 0.5s; } @property --color { syntax: "<color>"; initial-value: #3498db; } </style> <script> setInterval(() => { const color = `hsl(${Math.random()*360}, 70%, 60%)`; document.querySelector('.magic-box').style.setProperty('--color', color); }, 1000); </script>
📌 小贴士:
content-visibility
优化长页面性能 @starting-style
和transition
实现丝滑动画 scrollbar-gutter
提前占位滚动条空间 offset-path
和@property
,放心使用!
参考2025年8月最新前端教程及CSS新特性文档整理)本文由 云厂商 于2025-08-20发表在【云服务器提供商】,文中图片由(云厂商)上传,本平台仅提供信息存储服务;作者观点、意见不代表本站立场,如有侵权,请联系我们删除;若有图片侵权,请您准备原始证明材料和公证书后联系我方删除!
本文链接:https://xdh.7tqx.com/fwqgy/675719.html
发表评论