代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.content{
width: 500px;
height: 500px;
border: 1px solid red;
margin: 20px auto;
position: relative;
}
.line
{
position: relative;
}
.line::before{
content: "";
width: 5px;
height: 90px;
background-color: darkgreen;
position: absolute;
left: 35%;
top: 10px;
transition: transform;
transform: rotateZ(-30deg);
}
.line::after{
content: "";
width: 5px;
height: 90px;
background-color: darkgreen;
position: absolute;
right:35% ;
top: 10px;
transition: transform;
transform: rotateZ(30deg);
}
.head{
/*它的头是一个半圆,所以需要一个长方形*/
width: 250px;
height: 125px;
background-color: darkgreen;
margin-top: 50px;
margin-left: 25%;
border-radius: 125px 125px 0 0 ;
position: relative;/*绝对定位脱离文档流啊*/
}
.head::before{
content: "";
width: 30px;
height: 30px;
border-radius: 50%;
background-color: white;
position: absolute;
left: 50px;
top: 50px;
}
.head::after{
content: "";
width: 30px;
height: 30px;
border-radius: 50%;
background-color: white;
position: absolute;
right: 50px;
top: 50px;
}
.body{
width: 250px;
height: 250px;
margin: 10px auto;
margin-bottom: 0;
background-color: darkgreen;
position: relative;
}
.body::after,.body::before{
content: "";
position: absolute;
top: 20px;
background-color: darkgreen;
width: 30px;
height: 180px;
border-radius: 10px;
}
.body::after
{
left: -40px;
}
.body::before
{
right: -40px;
}
.footer
{
position: relative;
}
.footer::before,.footer::after
{
content: "";
margin-top: 0;
width: 20px;
height: 60px;
background-color: darkgreen;
position: absolute;
}
.footer::before{
left: 200px;
}
.footer::after
{
right: 200px;
}
</style>
</head>
<body>
<div class="content">
<div class="line"></div>
<div class="head"></div>
<div class="body"></div>
<div class="footer"></div>
</div>
</body>
</html>