CSS3實現太極圖案html
分析圖片組成(以下圖所示):git
先給出html代碼:github
<div class="box">
<div class="content">
<div class="left"></div>
<div class="right"></div>
<div class="inner-circle up">
<div class="sm-circle circle-white"></div>
</div>
<div class="inner-circle down">
<div class="sm-circle circle-black"></div>
</div>
</div>
</div>
步驟一:web
先把紫色框出來的兩個div修改其樣式,使其分別成兩個半圓,一黑一白。ide
.left{ position: absolute; width: 50%; top: 0; left:0; height: 100%; background-color: #000000; border-radius: 100% 0 0 100% / 50% 0 0 50%; } .right{ position: absolute; width: 50%; top: 0; right: 0;; height: 100%; background-color: #FFFFFF; border-radius: 0 100% 100% 0 / 0 50% 50% 0; }
步驟二:把外面的紅色框添加樣式,使其變成圓,一黑一白動畫
.inner-circle{ position: absolute; width: 50%; height: 50%; left: 25%; border-radius:50% ; } .up{ top: 0; background-color: #000000; } .down{ bottom: 0; background-color: #FFFFFF; }
第三步:給最裏面的紅色框添加樣式,使其變成圓,一黑一白spa
.sm-circle{ position: absolute; width: 25%; height: 25%; top: 37.5%; left: 37.5%; border-radius: 50%; } .circle-white{ background-color: #FFFFFF; } .circle-black{ background-color: #000; }
最後:給太極圖案最外層的div添加動畫,使其動起來3d
設置動畫code
@keyframes Rotate { 0%{ -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); transform: rotate(0deg); } 100%{ -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -ms-transform: rotate(360deg); transform: rotate(360deg); } }
給div綁定動畫orm
.content{ margin: 0 auto; position: relative; width: 300px; height: 300px; border-radius: 50%; background-color: #FFFFFF; border: 1px solid #aaa; animation: Rotate 6s linear infinite; }
好了,旋轉的太極就畫好了,是否是很簡單呀