通过css样式实现太极图的布局效果,利用transform实现动态旋转。:hover当鼠标放到图上时,反方向旋转。
<!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>
body {
background-color: #ccc;
}
.box {
margin: 100px auto;
position: relative;
width: 150px;
height: 300px;
background-color: #000;
border-left: 150px solid #fff;
border-radius: 50%;
transform-style: preserve-3d;
animation: rotate 10s linear infinite;
transition: all 3s;
}
.box::before {
position: absolute;
content: '';
width: 30px;
height: 30px;
border: 60px solid #fff;
background-color: #000;
margin-left: -75px;
border-radius: 50%;
}
.box::after {
position: absolute;
content: '';
width: 30px;
height: 30px;
border: 60px solid #000;
background-color: #fff;
margin-top: 150px;
margin-left: -75px;
border-radius: 50%;
}
@keyframes rotate {
form {
transform-style: rotateZ(0deg);
}
to {
transform: rotateZ(360deg);
}
}
.box:hover {
transform: rotateZ(1080deg);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>