Dev*_*Joe 6 html css css-shapes
我想用CSS修改这个矩形div/background的底部,所以结果是这样的:
.curved {
margin: 0 auto;
width: 800px;
height: 500px;
background: lightblue;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="curved"></div>
</div>Run Code Online (Sandbox Code Playgroud)
Tem*_*fif 15
只需使用边框半径并使元素溢出.您还可以依赖伪元素来避免额外的标记:
.container {
margin: 0 auto;
width: 500px;
height: 200px;
background: lightblue;
position: relative;
overflow: hidden;
}
.container:after {
content: "";
position: absolute;
height: 80px;
left: -10%;
right: -10%;
border-radius: 50%;
bottom: -25px;
background: #fff;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
</div>Run Code Online (Sandbox Code Playgroud)
您也可以使用径向渐变.如果您希望形状透明并且您的元素将在背景上方,那么这将是很好的:
body {
background: pink;
}
.container {
margin: 0 auto;
width: 500px;
height: 200px;
background: radial-gradient(110% 50% at bottom, transparent 50%, lightblue 51%);
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
</div>Run Code Online (Sandbox Code Playgroud)
这是使用clip-path的另一种方式(只需注意浏览器支持):
.container {
margin: 0 auto;
width: 500px;
height: 200px;
background-color: lightblue;
position: relative;
overflow: hidden;
}
.container:after {
content: "";
position: absolute;
bottom: 0;
right: -5%;
left: -5%;
height: 120px;
background: #fff;
-webkit-clip-path: ellipse(50% 60% at 50% 100%);
clip-path: ellipse(50% 60% at 50% 100%);
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
</div>Run Code Online (Sandbox Code Playgroud)
您也可以考虑使用SVG:
.container {
margin: 0 auto;
width: 500px;
height: 200px;
background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' width='64' height='48' fill='lightblue'><path d='M0 0 L0 16 C16 6 48 6 64 16 L64 0 Z' /></svg>") top center/auto 700px no-repeat;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
</div>Run Code Online (Sandbox Code Playgroud)
如果您还想在形状周围添加边框,这是一个示例:
.container {
margin: 0 auto;
width: 500px;
height: 200px;
border: 2px solid #000;
border-bottom: 0;
background: lightblue;
position: relative;
overflow: hidden;
}
.container:after {
content: "";
position: absolute;
height: 80px;
left: -10%;
right: -10%;
border-radius: 50%;
bottom: -62px;
background: #fff;
z-index: 2;
}
.container:before {
content: "";
position: absolute;
height: 82px;
left: -10%;
right: -10%;
border-radius: 50%;
bottom: -62px;
background: #000;
z-index: 1;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
</div>Run Code Online (Sandbox Code Playgroud)
检查这个。我用 :after 伪元素创建了这个。如果背景是纯色会很有帮助。
.curved {
margin: 0 auto;
width: 300px;
height: 300px;
background: lightblue;
position: relative;
}
.curved:after{
background: white;
position: absolute;
content: "";
left:0;
right:0;
bottom: -25px;
height: 50px;
border-radius: 50% 50% 0 0;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="curved"></div>
</div>Run Code Online (Sandbox Code Playgroud)