有趣的css - 太极八卦图

大家好,我是 Just,这里是「设计师工作日常」,今天分享的是用css 实现一个动态的太极八卦图。

《有趣的css》系列最新实例通过公众号「设计师工作日常」发布。


目录

  • 整体效果
  • 核心代码
    • html 代码
    • css 部分代码
  • 完整代码如下
    • html 页面
    • css 样式
    • 页面渲染效果

整体效果

知识点:
nth-of-type 选择器的使用
② 关于 transformtransform-origin 的使用方式
animation 动画和 animation-delay 延迟参数的使用

思路:先搭建太极阴阳鱼,利用 :before:after 伪元素画出阴阳鱼和鱼眼,然后分别绘制出八个卦象的图形,最后分别给太极阴阳鱼和卦象设置不同的动画参数。


核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。

核心代码

html 代码

<div class="taijibagua"><div class="taiji"><div class="yu"></div></div><div class="bagua" title="乾 - 天"></div><div class="bagua" title="兑 - 泽"><div class="white3"></div></div><div class="bagua" title="离 - 火"><div class="white2"></div></div><div class="bagua" title="震 - 雷"><div class="white2"></div><div class="white3"></div></div><div class="bagua" title="坤 - 地"><div class="white1"></div><div class="white2"></div><div class="white3"></div></div><div class="bagua" title="艮 - 山"><div class="white1"></div><div class="white2"></div></div><div class="bagua" title="坎 - 水"><div class="white1"></div><div class="white3"></div></div><div class="bagua" title="巽 - 风"><div class="white1"></div></div>
</div>

太极阴阳鱼以及八卦页面代码部分。

css 部分代码

.taijibagua{width: 200px;height: 200px;display: flex;justify-content: center;align-items: center;position: relative;
}
.taiji{width: 100px;height: 100px;position: relative;border-radius: 50%;box-shadow: 0px -5px 10px 0px rgba(42,245,152,0.4), 0px 5px 10px 0px rgba(8,174,234,0.4);animation: zhuan 5s linear infinite;
}
.taiji:before,.taiji:after{content: '';width: 100px;height: 50px;position: absolute;background-color: #fff;border-radius: 100px 100px 0 0;
}
.taiji:after{top: 50px;background-color: #000;border-radius: 0 0 50px 50px;
}
.yu:before,.yu:after{content: '';width: 12px;height: 12px;position: absolute;top: 25px;left: 50px;border-radius: 50%;background-color: #000;border: 19px solid #fff;z-index: 1;
}
.yu:after{left: 0;background-color: #fff;border: 19px solid #000;
}
@keyframes zhuan{to {transform: rotate(360deg);}
}
.bagua{width: 40px;height: 5px;background-color: #2AF598;position: absolute;top: 0;transform-origin: 20px 100px;animation: eff49 5s linear infinite;opacity: 0.2;
}
.bagua:before,.bagua:after{content: '';width: 40px;height: 5px;background-color: #08AEEA;position: absolute;top: 10px;
}
.bagua:after{top: 20px;background-color: #000;
}
.taijibagua .bagua:nth-of-type(3){transform: rotate(-45deg);animation-delay: 4.375s;
}
.taijibagua .bagua:nth-of-type(4){transform: rotate(-90deg);animation-delay: 3.75s;
}
.taijibagua .bagua:nth-of-type(5){transform: rotate(-135deg);animation-delay: 3.125s;
}
.taijibagua .bagua:nth-of-type(6){transform: rotate(-180deg);animation-delay: 2.5s;
}
.taijibagua .bagua:nth-of-type(7){transform: rotate(-225deg);animation-delay: 1.875s;
}
.taijibagua .bagua:nth-of-type(8){transform: rotate(-270deg);animation-delay: 1.25s;
}
.taijibagua .bagua:nth-of-type(9){transform: rotate(-315deg);animation-delay: 0.625s;
}
.white1,.white2,.white3{width: 10px;height: 7px;background-color: #ffffff;position: absolute;top: -1px;left: 50%;transform: translate(-50%,0);z-index: 10;
}
.white2{top: 10px;
}
.white3{top: 20px;
}
@keyframes eff49{0% {opacity: 1;}100%{opacity: 0.2;}
}

1、.taiji:before.taiji:after 伪元素分别绘制黑白阴阳鱼的主体, .yu:beforeyu:after 伪元素分别绘制黑白阴阳鱼的小鱼眼,然后设置旋转动画,顺时针旋转。

2、.bagua 配合 .bagua:before.bagua:after 绘制出三条矩形形状,然后利用不同的 .white1.white2.white3 去遮挡分割矩形,来实现不同的卦象

3、页面中的八个 .bagua 通过 transform-origin 定义旋转圆点,然后用 :nth-of-type(n) 选择器分别定义八个卦象的旋转角度,让八个卦象分布在太极阴阳鱼四周

4、最后定义动画参数且使用 animation-delay 来延迟每个卦象的动画启动时间,来实现卦象随着太极阴阳鱼旋转时,不停亮起的效果。

完整代码如下

html 页面

<!DOCTYPE html>
<html lang="zh"><head><meta charset="utf-8"><link rel="stylesheet" href="style.css"><title>太极八卦图</title></head><body><div class="app"><div class="taijibagua"><div class="taiji"><div class="yu"></div></div><div class="bagua" title="乾 - 天"></div><div class="bagua" title="兑 - 泽"><div class="white3"></div></div><div class="bagua" title="离 - 火"><div class="white2"></div></div><div class="bagua" title="震 - 雷"><div class="white2"></div><div class="white3"></div></div><div class="bagua" title="坤 - 地"><div class="white1"></div><div class="white2"></div><div class="white3"></div></div><div class="bagua" title="艮 - 山"><div class="white1"></div><div class="white2"></div></div><div class="bagua" title="坎 - 水"><div class="white1"></div><div class="white3"></div></div><div class="bagua" title="巽 - 风"><div class="white1"></div></div></div></div></body>
</html>

css 样式

/** style.css **/
.app{width: 100%;height: 100vh;background-color: #ffffff;position: relative;display: flex;justify-content: center;align-items: center;
}
.taijibagua{width: 200px;height: 200px;display: flex;justify-content: center;align-items: center;position: relative;
}
.taiji{width: 100px;height: 100px;position: relative;border-radius: 50%;box-shadow: 0px -5px 10px 0px rgba(42,245,152,0.4), 0px 5px 10px 0px rgba(8,174,234,0.4);animation: zhuan 5s linear infinite;
}
.taiji:before,.taiji:after{content: '';width: 100px;height: 50px;position: absolute;background-color: #fff;border-radius: 100px 100px 0 0;
}
.taiji:after{top: 50px;background-color: #000;border-radius: 0 0 50px 50px;
}
.yu:before,.yu:after{content: '';width: 12px;height: 12px;position: absolute;top: 25px;left: 50px;border-radius: 50%;background-color: #000;border: 19px solid #fff;z-index: 1;
}
.yu:after{left: 0;background-color: #fff;border: 19px solid #000;
}
@keyframes zhuan{to {transform: rotate(360deg);}
}
.bagua{width: 40px;height: 5px;background-color: #2AF598;position: absolute;top: 0;transform-origin: 20px 100px;animation: eff49 5s linear infinite;opacity: 0.2;
}
.bagua:before,.bagua:after{content: '';width: 40px;height: 5px;background-color: #08AEEA;position: absolute;top: 10px;
}
.bagua:after{top: 20px;background-color: #000;
}
.taijibagua .bagua:nth-of-type(3){transform: rotate(-45deg);animation-delay: 4.375s;
}
.taijibagua .bagua:nth-of-type(4){transform: rotate(-90deg);animation-delay: 3.75s;
}
.taijibagua .bagua:nth-of-type(5){transform: rotate(-135deg);animation-delay: 3.125s;
}
.taijibagua .bagua:nth-of-type(6){transform: rotate(-180deg);animation-delay: 2.5s;
}
.taijibagua .bagua:nth-of-type(7){transform: rotate(-225deg);animation-delay: 1.875s;
}
.taijibagua .bagua:nth-of-type(8){transform: rotate(-270deg);animation-delay: 1.25s;
}
.taijibagua .bagua:nth-of-type(9){transform: rotate(-315deg);animation-delay: 0.625s;
}
.white1,.white2,.white3{width: 10px;height: 7px;background-color: #ffffff;position: absolute;top: -1px;left: 50%;transform: translate(-50%,0);z-index: 10;
}
.white2{top: 10px;
}
.white3{top: 20px;
}
@keyframes eff49{0% {opacity: 1;}100%{opacity: 0.2;}
}

页面渲染效果

以上就是所有代码,以及简单的思路,希望对你有一些帮助或者启发。


[1] 原文阅读


CSS 是一种很酷很有趣的计算机语言,在这里跟大家分享一些 CSS 实例 Demo,为学习者获取灵感和思路提供一点帮助,希望你们喜欢。

我是 Just,这里是「设计师工作日常」,求点赞求关注!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/806994.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Netty出坑记

NIO&#xff1a; 一个线程处理多个请求 BIO&#xff1a; 阻塞 netty 编码解码 TFO&#xff1a; 校验cookie合法性&#xff0c;不合法 TCP流程 设计QQ&#xff1a; 登录过程&#xff0c;client TCP协议向server发送信息&#xff0c;HTTP协议下载信息 发消息&#xff1a;clie…

JS实现大数相加

概述 在JavaScript中&#xff0c;进行大数相加时&#xff0c;由于JavaScript的Number类型有一定的精度限制&#xff0c;直接相加可能会导致精度损失 解决方案 将大数转换为字符串&#xff0c;使用字符串拼接的方式实现大数相加&#xff0c;对相加后的字符串从低位到高位逐位求…

云服务器上Docker启动的MySQL会自动删除数据库的问题

一、问题说明 除了常见的情况&#xff0c;例如没有实现数据挂载&#xff0c;导致数据丢失外&#xff0c;还需要考虑数据库是否被攻击&#xff0c;下图 REVOVER_YOUR_DATA 就代表被勒索了&#xff0c;这种情况通常是数据库端口使用了默认端口&#xff08;3306&#xff09;且密码…

Harmony鸿蒙南向驱动开发-SDIO

SDIO&#xff08;Secure Digital Input and Output&#xff09;由SD卡发展而来&#xff0c;与SD卡统称为MMC&#xff08;MultiMediaCard&#xff09;&#xff0c;二者使用相同的通信协议。SDIO接口兼容以前的SD卡&#xff0c;并且可以连接支持SDIO接口的其他设备。 运作机制 …

力扣HOT100 - 54. 螺旋矩阵

解题思路&#xff1a; 设置四个边界 class Solution {public List<Integer> spiralOrder(int[][] matrix) {if (matrix.length 0) return new ArrayList<Integer>();int l 0;int r matrix[0].length - 1;int t 0;int b matrix.length - 1;List<Integer>…

动手学习深度学习(李沐)

文章目录 04.数据操作 04.数据操作 创建数组 形状 每个元素的数据类型 每个元素的值 数据操作

PyCharm如何调出Run窗口的搜索功能

搜索快捷键 搜索&#xff08;查找&#xff09;的快捷键默认有两个 Ctrl F Alt F3 只需要点击运行窗口的区域&#xff0c;再使用上面的快捷键就好了。 也可以在代码中查找&#xff0c;也是上述操作。 如果按了没反应怎么办&#xff1f; 1、可能是有些软件的某些功能的快捷…

使用Pandas解决问题:对比两列数据取最大值的五种方法

目录 一、使用max方法 二、使用apply方法结合lambda函数 三、使用np.maximum函数 四、使用clip方法 五、使用where方法结合条件赋值 总结&#xff1a; 在数据处理和分析中&#xff0c;经常需要比较两个或多个列的值&#xff0c;并取其中的最大值。Pandas库作为Python…

Linux(CentOS7)安装 Docker 以及 Docker 基本使用教程

目录 安装 基础依赖 安装 docker 开机自启 启动 docker 配置国内镜像源 使用教程 帮助命令 镜像命令 容器命令 容器终端 构建镜像 安装 基础依赖 如果直接安装 docker 时报错&#xff0c;提示缺少依赖&#xff0c;则根据提示将前置依赖安装即可&#xff0c;这里直…

计算机组成原理(存储器)

1、“821.2016T1(1)”&#xff0c;表示821真题&#xff0c;2016年的题&#xff0c;T1是 选择题/填空题/大题 的第一题&#xff0c;其他类似标记也是相通 2、个人小白总结自用&#xff0c;不一定适用于其他人&#xff0c;请自行甄别 3、有任何疑问&#xff0c;欢迎私信探讨&…

Stunnel网络加密服务

简介&#xff1a; Stunnel是一个用于创建SSL加密隧道的工具&#xff0c;针对本身无法进行TLS或SSL通信的客户端及服务器&#xff0c;Stunnel 可提供安全的加密连接。可以用于保护服务器之间的通信。您可以在每台服务器上安装Stunnel&#xff0c;并将其配置为在公网上加密传输数…

基于 SSM 数据结构课堂考勤管理系统的设计与实现

摘 要 高校的不断扩张让在校学生数量不断的增加&#xff0c;对于教师和管理人员的需求也在不断地增强&#xff0c;对日常的学生考勤管理的工作量也在日益增加&#xff0c;传统的人工点名签到的考勤管理模式已经给无法适用于当前高校考勤管理的需求&#xff0c;同时手动录入的…

C语言中的文件操作

C语言中的文件操作 1、文件的打开 创建文件指针变量 File* pf;定义一个指向FILE类型数据的指针变量&#xff0c;可以使pf指向某个文件的文件信息区&#xff0c;通过文件指针变量就能够找到与它关联的文件 &#xff08;1&#xff09;文件的打开 使用fopen函数打开文件&#…

关于招聘项目的常用方法类(PHP版)

1、最低工资与最高工资的数字转化为 几千到几千的形式 /*** param $minwage 最低工资* param $maxwage 最高工资* param int $negotiable 0表示具体工资&#xff0c;1表示面议* return string|string[]*/ public function handle_wage($minwage, $maxwage, $negotiable 0){$w…

Vue3---基础3(组合式API,setup语法糖)

选项式API与组合式API 在Vue2内是选项式API&#xff08;OptionsAPI&#xff09; 在Vue3内是组合式API&#xff08;CompositionAPI&#xff09; 选项式API 示例代码 <script lang"ts"> export default {name: person,data() {return {name: "张杰",a…

白盒测试-条件覆盖

​ 条件覆盖是指运行代码进行测试时&#xff0c;程序中所有判断语句中的条件取值为真值为假的情况都被覆盖到&#xff0c;即每个判断语句的所有条件取真值和假值的情况都至少被经历过一次。 ​ 条件覆盖率的计算方法为&#xff1a;测试时覆盖到的条件语句真、假情况的总数 / 程…

LLM(一):大语言模型

自2022年&#xff0c;ChatGPT发布之后&#xff0c;大语言模型&#xff08;Large Language Model&#xff09;&#xff0c;简称LLM掀起了一波狂潮。作为学习理解LLM的开始&#xff0c;先来整体的理解一下大语言模型 一&#xff0c;发展历史 大语言模型的发展历史可以追溯到早期…

【讲解下目标追踪】

&#x1f308;个人主页: 程序员不想敲代码啊 &#x1f3c6;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f44d;点赞⭐评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共…

【AI 测试】一:算法和数据结构理解

目录 算法和数据结构理解概念及实际列子一、排序算法概念冒泡排序 (Bubble Sort)选择排序 (Selection Sort)插入排序 (Insertion Sort)归并排序 (Merge Sort)快速排序 (Quick Sort)堆排序 (Heap Sort)计数排序 (Counting Sort)桶排序 (Bucket Sort)基数排序 (Radix Sort)二、查…

每日一题——环形链表的约瑟夫问题

题目链接&#xff1a; 环形链表的约瑟夫问题_牛客题霸_牛客网 题目&#xff1a; 描述 编号为 1 到 n 的 n 个人围成一圈。从编号为 1 的人开始报数&#xff0c;报到 m 的人离开。 下一个人继续从 1 开始报数。 n-1 轮结束以后&#xff0c;只剩下一个人&#xff0c;问最后留…