May 29, 2021 Article blog
A few days ago, the w3cschool compilation introduced
several common graphic painting methods.
So today we're going to show you how CSS draws five-pointed stars?
The application of five-pointed stars in web pages is still very common, such as our common favorite function, by drawing a pentix star, when the user taps the five-pointed star can light the five-pointed star, to achieve the collection effect.
Let's start with the implementation:
Idea: In fact, the idea of realizing a pentrophogram is to draw three triangles first, and then combine the three triangles, you can get a five-pointed star.
Specific code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS绘制五角星 - 编程狮(w3cschool.cn)</title>
<style type="text/css">
#star-five {
margin: 100px 0;
position: relative;
display: block;
color: red;
width: 0px; /*设置元素宽高为0*/
height: 0px;
border-right: 100px solid transparent; /*设置右部分为透明*/
border-bottom: 70px solid #ff0000; /*设置底部为红色*/
border-left: 100px solid transparent; /*设置左部分为透明*/
/*旋转角度为顺时针35度*/
-moz-transform: rotate(35deg); /*Firefox*/
-webkit-transform: rotate(35deg); /*Safari 和 Chrome*/
-ms-transform: rotate(35deg); /*IE 9*/
-o-transform: rotate(35deg); /*Opera*/
}
#star-five:before {
border-bottom: 80px solid #ff0000;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: '';
-webkit-transform: rotate(-35deg);
-moz-transform: rotate(-35deg);
-ms-transform: rotate(-35deg);
-o-transform: rotate(-35deg);
}
#star-five:after {
position: absolute;
display: block;
color: red;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid #ff0000;
border-left: 100px solid transparent;
-webkit-transform: rotate(-70deg);
-moz-transform: rotate(-70deg);
-ms-transform: rotate(-70deg);
-o-transform: rotate(-70deg);
content: '';
}
</style>
</head>
<body>
<div id="star-five"></div>
</body>
</html>
These are the full answers to how CSS draws five-pointed stars. For more CSS graphics, follow w3cschool.com.
Read more: How does CSS achieve a mouse-slip text effect? /b10> How does CSS achieve photo blur?