首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

  • 24-12-05 23:25
  • 2627
  • 9411
juejin.cn

这段代码通过 HTML 和 CSS 的结合,创建了一个动态的花朵效果,展示了 CSS 动画和定位的强大功能。

演示效果

HTML&CSS

html
代码解读
复制代码
html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>前端Hardytitle> <style> body { background-color: #21324C; color: #fff; font-family: 'Indie Flower', cursive; display: flex; justify-content: center; align-items: center; flex-direction: column; height: 100vh; } .text { margin-top: -300px; margin-bottom: 150px; text-align: center; } .text h1 { margin: 5px 0; } .text h3 { margin: 0; } .text a { color: #d52d58; text-decoration: none; } .flower { position: relative; top: -80px; left: -20px; } .flower:nth-of-type(2) { left: -80px; top: -19px; transform: scale(.7); } .flower:nth-of-type(3) { left: 55px; top: -19px; transform: scale(.7); } .flower .petal { position: absolute; top: 0; left: 0; background-color: #d52d58; border-radius: 0px 30px 0px 30px; width: 30px; height: 60px; } .flower .petal:nth-child(1) { left: -10px; transform: rotate(-10deg); transform-origin: bottom right; background-color: #b81b43; animation: openleft 3s ease-in infinite; z-index: 5; } .flower .petal:nth-child(2) { left: -10px; background-color: #c9204b; z-index: 4; } .flower .petal:nth-child(3) { border-radius: 30px; left: 5px; } .flower .petal:nth-child(4) { border-radius: 30px 0px 30px 0px; background-color: #c9204b; left: 20px; z-index: 4; } .flower .petal:nth-child(5) { border-radius: 30px 0px 30px 0px; left: 20px; transform: rotate(10deg); transform-origin: bottom left; animation: openright 3s ease-in infinite; background-color: #b81b43; z-index: 5; } .flower .rod { background-color: #329932; width: 5px; height: 150px; position: absolute; left: 17.5px; top: 58px; z-index: -1; } .flower .rod::before { background-color: lightgreen; border-radius: 3px; content: ''; display: block; width: 20px; height: 8px; margin-left: -8px; } .flower .rod .spike { width: 0; height: 0; position: absolute; top: 20px; left: -10px; border-color: transparent #329932 transparent transparent; border-style: solid; border-width: 5px; } .flower .rod .spike:nth-child(2) { top: 50px; left: 4px; border-color: transparent transparent transparent #329932; } .flower .rod .spike:nth-child(3) { top: 80px; } .flower .rod .spike:nth-child(4) { top: 110px; left: 4px; border-color: transparent transparent transparent #329932; } @keyframes openleft { 20%, 80% { transform: rotate(-20deg); } } @keyframes openright { 20%, 80% { transform: rotate(20deg); } } style> head> <body> <div class="flower"> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="rod"> <div class="spike">div> <div class="spike">div> <div class="spike">div> <div class="spike">div> div> div> <div class="flower"> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="rod"> <div class="spike">div> <div class="spike">div> <div class="spike">div> <div class="spike">div> div> div> <div class="flower"> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="petal">div> <div class="rod"> <div class="spike">div> <div class="spike">div> <div class="spike">div> <div class="spike">div> div> div> body> html>
  • .flower 设置花朵的位置和布局。position: relative; 相对定位。top: -80px; 和 left: -20px; 调整花朵的位置。
  • .flower .petal 设置花瓣的样式。position: absolute; 绝对定位。background-color: #d52d58; 背景颜色为粉红色。border-radius: 0px 30px 0px 30px; 设置边框圆角。
  • .flower .petal 子选择器根据不同的花瓣子元素,设置不同的样式,如旋转角度、背景颜色等。
  • .flower .rod 设置花杆的样式。background-color: #329932; 背景颜色为绿色。width: 5px; 宽度为 5px。height: 150px; 高度为 150px。
  • .flower .rod::before 设置花杆顶部的装饰。background-color: lightgreen; 背景颜色为浅绿色。
  • .flower .rod .spike 设置花杆上的刺。border-color: transparent #329932 transparent transparent; 设置边框颜色,形成三角形的刺。
  • @keyframes openleft 和 @keyframes openright 定义关键帧动画,用于创建花瓣的开合效果。
注:本文转载自juejin.cn的前端Hardy的文章"https://juejin.cn/post/7444732684923977739"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

104
前端
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top