老师为什么我制作过程中如果不在before或after设置定位就不会出现内容?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>2-5</title>
<style type="text/css">
div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
box-sizing: border-box;
width: 400px;
height: 400px;
margin: auto;
border: 1px solid red;
border-bottom: 200px solid red;
border-radius: 50%;
transform-origin: 50% 50%;
animation-name: rotate;
animation-duration: 5s;
animation-timing-function: linear;
/*此处写代码*/
animation-delay:0s;
animation-iteration-count:infinite;
}
@keyframes rotate{
from{transform:rotate(0deg);}
to{transform:rotate(360deg);}
}
div:before{
content:" ";
width:20px;height:20px;position: absolute;
background:white;
border: 90px solid red;
border-radius: 50%;
top: 100px;
}
div:after{
content:"";
width: 20px;height: 20px;position: absolute;
background: red;
border: 90px solid white;
border-radius: 50%;
right: 0px;top: 100px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
正在回答
同学你好,是的,因为伪元素是行内元素,不能设置宽高,在设置了绝对定位后就变成了块级元素,就可以设置宽高看到中心小圆了。
如果我的回答帮助了你,欢迎采纳,祝学习愉快~


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星