效果如图
主要通过上下两个椭圆定位,中间一个矩形实现,椭圆通过圆角border-radius: 50% / 50%; 实现
<!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">
<title>yuanzhu</title>
<style>
.container{
width: 140px;
margin: 100px auto;
position: relative;
}
.square{
width: 140px;
height: 150px;
background: linear-gradient(to right, #aaa,#fff,#aaa)
}
div[class^='circle']{
position: absolute;
left: 0;
width: 140px;
height: 30px;
/* 椭圆 */
border-radius: 50% / 50%;
background: linear-gradient(to right, #aaa,#fff,#aaa)
}
.circle1{
top: -15px;
}
.circle2{
bottom: -15px;
}
.center{
position: absolute;
width: 30px;
height: 120px;
background: linear-gradient(to right, rgb(69, 221, 115),rgb(203, 243, 194),rgb(69, 221, 115));
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
border: 3px solid #fff;
}
</style>
</head>
<body>
<div class="container">
<div class="square"></div>
<div class="circle1"></div>
<div class="circle2"></div>
<div class="center"></div>
</div>
</body>
</html>