CSS+html制作旋转的太极
一、制作太极
1.css画出太极
<!DOCTYPE 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>旋转的太极</title>
<style type="text/css">
.taiji {
width: 0px;
height: 400px;
border-left: 200px #eee solid;
border-right: 200px #000 solid;
/* 圆角 */
border-radius: 50%;
}
.xby {
/* 小白圆 */
width: 20px;
height: 20px;
background: #000;
border: 90px #eee solid;
border-radius: 50%;
/* 向左挪100px */
margin-left: -100px;
}
.xhy {
/* 小黑圆 */
width: 20px;
height: 20px;
background: #eee;
border: 90px #000 solid;
border-radius: 50%;
/* 向左挪100px */
margin-left: -100px;
}
</style>
</head>
<body>
<div class="taiji">
<div class="xby"></div>
<div class="xhy"></div>
</div>
</body>
</html>
2.利用伪元素画太极
<!DOCTYPE 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>伪元素制作太极</title>
<style type="text/css">
.taiji {
width: 0px;
height: 400px;
border-left: 200px #eee solid;
border-right: 200px #000 solid;
border-radius: 50%;
position: relative;
}
.taiji:before {
content: "";
width: 20px;
height: 20px;
background: #000;
border: 90px #eee solid;
border-radius: 50%;
position: absolute;
margin-left: -100px;
}
.taiji:after {
content: "";
width: 20px;
height: 20px;
background: #eee;
border: 90px #000 solid;
border-radius: 50%;
position: absolute;
margin-top: 200px;
margin-left: -100px;
}
</style>
</head>
<body>
<div class="taiji">
</div>
</body>
</html>
二、让太极旋转
添加动画animation和@keyframes设置旋转
以第一种为例
<!DOCTYPE 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>旋转的太极</title>
<style type="text/css">
.taiji {
/* 动画:动画名称、动画持续时间、动画速度:匀速、执行次数:无数次 */
animation: tjxz 5s linear infinite;
width: 0px;
height: 400px;
border-left: 200px #eee solid;
border-right: 200px #000 solid;
/* 圆角 */
border-radius: 50%;
}
.xby {
/* 小白圆 */
width: 20px;
height: 20px;
background: #000;
border: 90px #eee solid;
border-radius: 50%;
/* 向左挪100px */
margin-left: -100px;
}
.xhy {
/* 小黑圆 */
width: 20px;
height: 20px;
background: #eee;
border: 90px #000 solid;
border-radius: 50%;
/* 向左挪100px */
margin-left: -100px;
}
/* 动画 */
@keyframes tjxz {
/* 太极旋转从0度到359度 */
from {
transform: rotate(0deg);
}
/* 因为第360度就是0度,所以只要到359度 */
to {
transform: rotate(359deg);
}
}
</style>
</head>
<body>
<div class="taiji">
<div class="xby"></div>
<div class="xhy"></div>
</div>
</body>
</html>