简体   繁体   English

CSS,将内圈剪辑到图像

[英]CSS, Clip inner circle to image

I'm trying to use a "clip path" on an image with a rounded bottom section.我试图在带有圆形底部的图像上使用“剪辑路径”。 I try with svg clip paths, but the cut it's a outer circle ,i don't know if is the best approach because the clip is outer and not inner what do you recommend to achieve this?我尝试使用 svg 剪辑路径,但它是一个外圆,我不知道是否是最好的方法,因为剪辑是外部的而不是内部的,您建议如何实现这一点?

I want to achive this ->我想达到这个 ->

This is the codepen where i try to make it:这是我尝试制作的代码笔:

 .section-test { padding: 25px 0; background-image: url(https://res.cloudinary.com/ddioeulgw/image/upload/v1548437500/test/hero.png); background-size: cover; height: 85vh; clip-path: ellipse(85% 100% at 50% 0%); }
 <section class="section-test"> </section>

https://codepen.io/kenmarquez-the-typescripter/pen/ombege https://codepen.io/kenmarquez-the-typescripter/pen/ombege

I want to achive this ->我想达到这个 ->

This is how I would do it: I would use an SVG element.这就是我的做法:我将使用 SVG 元素。 The clipPath have clipPathUnits="objectBoundingBox" and the path have all it's values between 0 and 1. clipPath 具有clipPathUnits="objectBoundingBox"并且路径具有 0 到 1 之间的所有值。

 svg{position:absolute} .section-test { padding: 25px 0; background-image: url(https://res.cloudinary.com/ddioeulgw/image/upload/v1548437500/test/hero.png); background-size: cover; height: 85vh; clip-path: url(#clip); }
 <svg height="0" width="0" > <defs> <clipPath id="clip" clipPathUnits="objectBoundingBox"> <path d="M0,0 L0,.5 A1,1 0 0 1 1,.5 L1,0 0,0" /> </clipPath> </defs> </svg> <section class="section-test"> </section>

I hope it helps.我希望它有帮助。

clipPathUnits="objectBoundingBox" : This value indicates that all coordinates inside the element are relative to the bounding box of the element the clipping path is applied to. clipPathUnits="objectBoundingBox" :该值表示元素内的所有坐标都相对于应用剪切路径的元素的边界框。 It means that the origin of the coordinate system is the top left corner of the object bounding box and the width and height of the object bounding box are considered to have a length of 1 unit value.这意味着坐标系的原点是对象边界框的左上角,对象边界框的宽度和高度被认为具有 1 个单位值的长度。

MDN quote MDN 报价

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM