[英]Sharp corner curved background image
been thinking of what would be the best way to achieve a background image with a sharp corners. 一直在思考什么是获得带有尖角的背景图像的最佳方法。 I tried some css like
border-radius
and clip-path
but no luck. 我尝试了一些CSS,例如
border-radius
和clip-path
但是没有运气。 I guess clip-path
is the nearest possible answer but can't get it. 我猜想
clip-path
是最可能的答案,但无法理解。 Please see my sample below. 请在下面查看我的示例。
.main-header { background: url('http://placehold.it/150x150') no-repeat center center; background-position: 0% 33%; background-size: cover; min-height: 480px; border-radius: 0 0 45% 45%; }
<div class="main-header"> <br> </div>
if you can use image by img, not background. 如果可以通过img而不是背景使用图片。 I think you can try "clip-path" as below.
我认为您可以尝试如下的“剪切路径”。
HTML: HTML:
<div class="main-header">
<img src="http://placehold.it/150x150">
</div>
CSS: CSS:
img {
-webkit-clip-path: circle(100% at 50% 0);
clip-path: circle(100% at 50% 0);
}
and this site is useful to make clip-path ( http://bennettfeely.com/clippy/ ) 这个网站对于制作剪切路径很有用( http://bennettfeely.com/clippy/ )
You can use below code for it 您可以使用以下代码
Add border-bottom-left-radius:60% 30%; border-bottom-right-radius:60% 30%;
添加
border-bottom-left-radius:60% 30%; border-bottom-right-radius:60% 30%;
border-bottom-left-radius:60% 30%; border-bottom-right-radius:60% 30%;
css. CSS。 You can play with radius properties to know how it works..
您可以使用radius属性来了解其工作原理。
.main-header { background: url('http://placehold.it/150x150') no-repeat center center; background-position: 0% 33%; background-size: cover; min-height: 480px; border-bottom-left-radius:60% 30%; border-bottom-right-radius:60% 30%; }
<div class="main-header"> <br> </div>
How about this approach? 这种方法怎么样? JSBin
JSBin
body { background: white; margin: 0; } .main-header { background: url('http://www.stevensegallery.com/g/400/200') no-repeat center center; background-position: center; background-size: cover; min-height: 480px; position: relative; } .main-header::after { content: ''; display: block; position: absolute; background: transparent; /* You can play around with these numbers to adjust the curve */ bottom: -4rem; left: -25%; width: 150%; height: 400px; border-bottom: solid 4rem white; border-radius: 0 0 50% 50%; }
<div class="main-header"> <br> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.