简体   繁体   English

使用 a:before background 反转边框半径?

[英]Inverted border radius using a :before background?

I want to do an inverted border radius using a background, like so:我想使用背景做一个反转的边框半径,如下所示:

想要的形状

Here is my code:这是我的代码:

 .curved { background: #D3041E; height: 200px; width: 100%; position: relative; }.curved::before { content: ''; border-bottom-left-radius: 50% 100%; border-bottom-right-radius: 50% 100%; position: absolute; top: 0; width: 100%; background: #fff; height: 3%; }
 <div class="curved"> </div>

and here's what I get so far:这是我到目前为止得到的:

当前形状

Since you have no fine control on the curve made by border radius, the next best option could be drawing splines with svg.由于您无法很好地控制由边界半径制成的曲线,因此下一个最佳选择可能是使用 svg 绘制样条曲线。

I made a very simple path for the sake of this example.为了这个例子,我做了一个非常简单的路径。 There are further details here:这里有更多细节:

https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths

Frankly speaking the path I chose doesn't perfectly match with your expected result, anyway feel free to walk through this path (no pun intended) if you can't find the solution aimed for using the magics of borders坦率地说,我选择的路径与您的预期结果并不完全匹配,无论如何,如果您找不到旨在使用边界魔法的解决方案,请随意走这条路(没有双关语)

 .curved{ background: #D3041E; height: 200px; width: 100%; position: relative; }
 <div class="curved"> <svg width="100%" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> <path d="M 0 0 C 25 10, 75 10, 100 0" fill="white" /> </svg> </div>

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

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