如何在CSS中实现曲线背景?
我有一个具有曲线背景的着陆页。请参考以下图像。从CSS编码时,我想知道最好的方法。我还需要做出响应迅速,并且我将Bootstrap用作CSS框架。以下是我所做的。
我已经使用了SVG图像作为背景,并将其用于以下方式:在伪级之前显示在底部。而且,我还从SVG中删除了宽度和高度,并保留了视图框,并将PreserveSpectratio =“ Xminymin Meets”添加到SVG中,以使其响应能力。 (请注意,这些属性未添加到JSFIDDLE中的示例中)
创建这些弯曲背景的最佳方法是什么?
.hero-container {
background-image: url(https://images.unsplash.com/photo-1581362508717-f542c1ecf295?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80);
background-size: cover;
background-repeat: no-repeat;
background-position: top center;
padding: 16.625rem 0;
}
.hero-container:after {
content: url('http://svgshare.com/i/Hud.svg');
position: absolute;
width: 100%;
height: auto;
bottom: -85px;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<section class="hero-container position-relative">
<div class="container">
<div class="row">
<div class="col-md-7 col-xs-12">
<h1 class="mb-3">Lorem ipsum dolor sit amet</h1>
<p class="mb-4 text-white">Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet</p>
<button class="btn btn-secondary">Register My Club</button>
</div>
</div>
</div>
</section>
I have a landing page with a curve background. Please refer to the following image. I would like to know the best approach when coding this from CSS. I also need to make this responsive and I'm using bootstrap as a CSS framework. Following is what I have done.
I have used an SVG image as the background and used it with :before pseudo-class to display in the bottom. And also I have removed width and height from the SVG and kept the view box and added preserveAspectRatio="xMinYMin meet" to SVG to make it responsive. (Please note these attributes not added to the example in JSFiddle)
What is the best approach to create these curvy backgrounds?
.hero-container {
background-image: url(https://images.unsplash.com/photo-1581362508717-f542c1ecf295?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80);
background-size: cover;
background-repeat: no-repeat;
background-position: top center;
padding: 16.625rem 0;
}
.hero-container:after {
content: url('http://svgshare.com/i/Hud.svg');
position: absolute;
width: 100%;
height: auto;
bottom: -85px;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<section class="hero-container position-relative">
<div class="container">
<div class="row">
<div class="col-md-7 col-xs-12">
<h1 class="mb-3">Lorem ipsum dolor sit amet</h1>
<p class="mb-4 text-white">Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet</p>
<button class="btn btn-secondary">Register My Club</button>
</div>
</div>
</div>
</section>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将考虑与先前答案使用
mask
和径向梯度。只需调整两个变量,直到获得所需的结果:
要理解技巧
bask
background
:将其应用于您的代码:
I will consider the same idea as this previous answer to create the curve using
mask
andradial-gradient
. Simply adjust both variables until you get the needed result:To understand the trick replace the
mask
withbackground
:Applying this to your code: