实现效果如下:图片的四边都有圆弧效果
实现原理:
- 利用border-radius给第一个元素实现上圆弧和下圆弧,再给第二个元素实现左圆弧和右圆弧,通过计算大致使其圆弧能够拼接到一起
- 元素使用伪元素,再分别给其设置背景图片,从而拼成圆弧效果
<!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>
.container {
margin: 8px;
position: relative;
width: 84px;
height: 84px;
background-color: #fff;
}
.container::before {
content: "";
position: absolute;
top: -8px;
left: 0;
right: 0;
bottom: -8px;
border-top-left-radius: 84px 24px;
border-top-right-radius: 84px 24px;
border-bottom-right-radius: 84px 24px;
border-bottom-left-radius: 84px 24px;
background: url('./1.jpg') no-repeat;
background-size: 100px 100px;
background-position: center center;
}
.container::after {
content: "";
position: absolute;
top: 0;
left: -8px;
right: -8px;
bottom: 0;
border-top-left-radius: 24px 84px;
border-top-right-radius: 24px 84px;
border-bottom-right-radius: 24px 84px;
border-bottom-left-radius: 24px 84px;
background: url('./1.jpg') no-repeat;
background-size: 100px 100px;
background-position: center center;
}
</style>
</head>
<body>
<div class="container"></div>
</body>
</html>