
HTMLPart2Demo代码
<!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 {
border: 48px solid white;
border-bottom-color: #ed5a65;
border-radius: 50%;
animation: rotation 1s linear infinite;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
Part3原理详解
步骤1
使用span标签,设置
- 边框:48px 白色 solid
效果图如下

注:这里没有设置width、height,仅使用了border就生成了一个正方形
为了理解其中的原理
我们设置span
- 宽度、高度均为36px,背景色为green
- 上边框:48px solid aquamarine
- 下边框:48px solid red
- 左边框:48px solid white
- 右边框:48px solid color:yellow
width: 36px;
height: 36px;
/* span背景色 */
background-color: green;
border: 48px solid ;
/* 上边框颜色 */
border-top-color: aquamarine;
/* 下边框颜色 */
border-bottom-color: red;
/* 左边框颜色 */
border-left-color: white;
/* 右边框颜色 */
border-right-color:yellow ;
效果如下

通过检查span元素
我们发现此时span元素宽度、高度变为了132px
这是因为有了边框
132px=36px+48px+48px

再不断减小span初始宽度、高度
直到为0
只剩下了border
border: 48px solid ;
/* 上边框颜色 */
border-top-color: aquamarine;
/* 下边框颜色 */
border-bottom-color: red;
/* 左边框颜色 */
border-left-color: white;
/* 右边框颜色 */
border-right-color:yellow ;
效果如下

现在可以理解步骤1的原理了吧
步骤2
下边框颜色设置为红色
border-bottom-color: #ed5a65;
效果图如下

步骤3
span圆角化
border-radius: 50%;
效果图如下

步骤4
为span添加动画
- 顺时针旋转(0度-360度) 1s 无限循环
animation: rotation 1s linear infinite;
@keyframes rotation {
0% {
transform: rotate(0deg)
}
100% {
transform: rotate(360deg)
}
}
效果图如下

https://mp.weixin.qq.com/s/a5VhY5GzDXtEkF8w3xN3QQ
















