效果展示
思路这里用span元素代表外层白色圆圈
两个红色小球分别用span的两个伪类::before和::after代表
根据效果图,可以大概得出思路
HTML
<!DOCTYPE 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-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
animation: rotation 2s linear infinite;
}
span::before{
position: absolute;
content: '';
top: 15px;
left: 15px;
width: 20px;
height: 20px;
background: red;
border-radius: 50%;
}
span::after{
position: absolute;
content: '';
bottom: 15px;
right: 15px;
width: 20px;
height: 20px;
background: red;
border-radius: 50%;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
原理详解步骤1
将span元素设置为
width : 96px;
height: 96px;
border: 10px solid #fff;
效果图如下
步骤2span::before和span::after设置
/* before的设置*/
position: absolute;
content: '';
top: 0;
left: 0;
width: 20px;
height: 20px;
background: red;
/*after的设置*/
position: absolute;
content: '';
bottom: 0;
right: 0;
width: 20px;
height: 20px;
background: red;
效果图如下
在这里插入图片描述
步骤3稍微向正方形中心移动下::before和::after
/* before的设置*/
top: 15px;
left: 15px;
/*after的设置*/
bottom: 15px;
right: 15px;
效果图如下
在这里插入图片描述
步骤4对span、span::before、span::after设置圆角
border-radius: 50%;
效果图如下
步骤7为span添加动画
animation: rotation 1s linear infinite;
/*动画实现*/
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
效果图如下
在这里插入图片描述
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved