前言
Hello吸耿!小伙伴!
首先非常感謝您閱讀海轟的文章酷窥,倘若文中有錯(cuò)誤的地方咽安,歡迎您指出~
哈哈 自我介紹一下
昵稱:海轟
標(biāo)簽:程序猿一只|C++選手|學(xué)生
簡(jiǎn)介:因C語(yǔ)言結(jié)識(shí)編程,隨后轉(zhuǎn)入計(jì)算機(jī)專(zhuān)業(yè)蓬推,有幸拿過(guò)國(guó)獎(jiǎng)板乙、省獎(jiǎng)等,已保研。目前正在學(xué)習(xí)C++/Linux(真的真的太難了~)
學(xué)習(xí)經(jīng)驗(yàn):扎實(shí)基礎(chǔ) + 多做筆記 + 多敲代碼 + 多思考 + 學(xué)好英語(yǔ)募逞!
效果展示
Demo代碼
HTML
<!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">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section><span></span></section>
</body>
</html>
CSS
html,body{
margin: 0;
height: 100%;
}
body{
display: flex;
justify-content: center;
align-items: center;
background: #263238;
}
section {
width: 650px;
height: 300px;
padding: 10px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
/* 紅色邊框僅作提示 */
border: 2px solid red;
}
span{
width : 96px;
height: 96px;
border: 10px solid white;
border-style: solid solid dotted dotted ;
border-radius: 50%;
position: relative;
display: flex;
align-items: center;
justify-content: center;
animation: rotation 2s linear infinite;
}
span::before{
position: relative;
content: '';
width: 48px;
height: 48px;
border: 10px red solid;
border-style: solid solid dotted ;
border-radius: 50%;
/* 注意這里的時(shí)間 */
animation: rotationback 1s linear infinite;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
@keyframes rotationback {
0% { transform: rotate(360deg) }
100% { transform: rotate(0deg)
}
}
原理詳解
步驟1
使用span標(biāo)簽作為外圍白色部分蛋铆,并設(shè)置
- 寬度、高度均為96px
- 邊框:白色 10px solid
width : 96px;
height: 96px;
border: 10px solid white;
效果圖如下
步驟2
設(shè)置span邊框
- 上/右邊框?yàn)閟olid
- 下/左邊框?yàn)閐otter(點(diǎn)狀)
border-style: solid solid dotted dotted ;
效果圖如下
步驟3
使用span::before作為紅色部分放接,并設(shè)置
- 相對(duì)定位
- 寬度刺啦、高度均為48px
- 邊框:10px 紅色 solid
- 位于白色正方形 正中間(這里使用的是:在span中使用flex布局)
width: 48px;
height: 48px;
border: 10px red solid;
效果圖如下
步驟4
設(shè)置span::before邊框
- 下邊框?yàn)閐otted
- 其余為solid
border-style: solid solid dotted ;
效果圖如下
步驟5
span、span::before圓角化
border-radius: 50%;
效果圖如下
步驟6
為span添加動(dòng)畫(huà)
- 順時(shí)針 2s 無(wú)限循環(huán)
animation: rotation 2s linear infinite;
/*動(dòng)畫(huà)實(shí)現(xiàn)*/
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
效果圖如下
步驟7
為span::before設(shè)置動(dòng)畫(huà)
-逆時(shí)針 1s 無(wú)限循環(huán)
/*注意時(shí)間*/
animation: rotationback 1s linear infinite;
/*動(dòng)畫(huà)實(shí)現(xiàn)*/
@keyframes rotationback {
0% { transform: rotate(360deg) }
100% { transform: rotate(0deg)
}
}
效果圖如下
結(jié)語(yǔ)
學(xué)習(xí)來(lái)源:
文章僅作為學(xué)習(xí)筆記纠脾,記錄從0到1的一個(gè)過(guò)程玛瘸。希望對(duì)您有所幫助,如有錯(cuò)誤歡迎小伙伴指正~
我是海轟?(?ˊ?ˋ)?苟蹈,如果您覺(jué)得寫(xiě)得可以的話糊渊,請(qǐng)點(diǎn)個(gè)贊吧
寫(xiě)作不易,「點(diǎn)贊」+「收藏」+「轉(zhuǎn)發(fā)」
謝謝支持??