简体   繁体   English

带有实心边框的 CSS 插入边框半径

[英]CSS inset border radius with solid border

I know that I could create inset/inverted borders playing with radial-gradient, like here: Inset border-radius with CSS3 , but what I want to know is if I can draw a solid border of 1px around the resulting shape, like in this image:我知道我可以使用径向渐变创建插入/倒置边框,就像这里: Inset border-radius with CSS3 ,但我想知道的是我是否可以在结果形状周围绘制 1px 的实心边框,就像这样图像:
在此处输入图片说明

I don't only want the bottom-left radius inverted by also a border, and the background color inside the remaining space must be transparent.我不仅希望左下角半径也被边框反转,并且剩余空间内的背景颜色必须是透明的。 Is it possible with CSS3 and HTML (I am not interested in canvas or SVG for now)?是否可以使用 CSS3 和 HTML(我现在对画布或 SVG 不感兴趣)?

the demo: Jsfiddle here演示: Jsfiddle在这里

Code代码

 figure { position: relative; width: 200px; height: 120px; margin: 100px auto; overflow: hidden; border: 1px solid black; border-right: none; border-bottom: none; border-bottom-left-radius: 5px; border-top-left-radius: 5px; } figure:before, figure:after { content: ''; position: absolute; } figure:before { right: -50%; top: 0; background: transparent; width: 172px; height: 200px; border: 1px solid black; border-radius: 100%; box-shadow: 0 0 0 100em red; } figure:after { left: -1px; bottom: 0px; height: 16px; width: 128px; border-top-left-radius: 0; border-bottom-left-radius: 5px; border-left: 1px solid black; border-bottom: 1px solid black; }
 <figure></figure>

In my experience, while it's very feasible and worthwhile to use CSS to create some complex shapes ( http://css-tricks.com/examples/ShapesOfCSS/ ), once you require a border, it's time to give up this method and use images.以我的经验,虽然使用 CSS 来创建一些复杂的形状是非常可行和值得的( http://css-tricks.com/examples/ShapesOfCSS/ ),但是一旦你需要一个边框,是时候放弃这种方法并使用图片。 You can certainly use a clone of the shape z-indexed below it, two pixels wider, two pixels taller, one pixel above it, one pixel to the left, and in the desired border color.您当然可以在其下方使用 z 索引形状的克隆,宽两个像素,高两个像素,上方一个像素,左侧一个像素,并使用所需的边框颜色。 Unfortunately, there will always be minor cross browser issues, especially with rounding.不幸的是,总会有一些小的跨浏览器问题,尤其是四舍五入。 It will never really look quite right.它永远不会看起来很正确。

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

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