In this tutorial we will be Drawing Stars using HTML and CSS. We have used border and position properties of CSS for this purpose.
Table of Contents
HTML Code
HTML Code is given below.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>Drawing Stars using HTML and CSS</title>
</head>
<body>
<div>
<span class='star'></span>
<span class='star'></span>
<span class='star'></span>
<span class='star'></span>
<span class='star'></span>
</div>
</body>
</html>
CSS Code
CSS Code is given below.
body
{
margin: 0;
padding: 0;
background-color: #22438c;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.star
{
margin: 20px;
display: inline-block;
width: 0px;
height: 0px;
border-right: 45px solid transparent;
border-bottom: 40px solid #FFCC00;
border-left: 45px solid transparent;
transform: rotate(35deg);
cursor: pointer;
}
.star:before {
position: absolute;
display: inline-block;
left:-32px;
top:-20px;
width: 0px;
height: 0px;
border-right: 16px solid transparent;
border-bottom: 35px solid #FFCC00;
border-left: 16px solid transparent;
content: '';
transform: rotate(-34deg);
cursor:pointer;
}
.star:after {
position: absolute;
display: inline-block;
left:-45px;
top:0px;
width: 0px;
height: 0px;
border-right: 45px solid transparent;
border-bottom: 40px solid #FFCC00;
border-left: 45px solid transparent;
content: '';
transform: rotate(-70deg);
cursor:pointer;}
Demo
Video Tutorial
Watch video tutorial on Drawing Stars using HTML and CSS.
Post a Comment