2023-06-06 05:00:00

轮廓半径?

是否有任何方法在div元素的轮廓上获得圆角,类似于border-radius?


当前回答

我通常使用:after伪元素来完成这个任务:

当然,这取决于使用情况,这种方法允许控制单个边界,而不是使用硬阴影方法。

你也可以设置-1px偏移量,并使用背景线性渐变(无边框)再次获得不同的效果。

身体{ 保证金:20 px; } 一个{ 背景:# 999; 填充:10px 20px; border - radius: 5 px; 文字修饰:没有; 颜色:# fff; 位置:相对; 边框:2px实心#000; } {后 内容:”; 显示:块; 位置:绝对的; 上图:0; 底部:0; 左:0; 右:0; border - radius: 5 px; 边框:2px实体#ccc; } < a href = " # " > < / >按钮

其他回答

我通常使用:after伪元素来完成这个任务:

当然,这取决于使用情况,这种方法允许控制单个边界,而不是使用硬阴影方法。

你也可以设置-1px偏移量,并使用背景线性渐变(无边框)再次获得不同的效果。

身体{ 保证金:20 px; } 一个{ 背景:# 999; 填充:10px 20px; border - radius: 5 px; 文字修饰:没有; 颜色:# fff; 位置:相对; 边框:2px实心#000; } {后 内容:”; 显示:块; 位置:绝对的; 上图:0; 底部:0; 左:0; 右:0; border - radius: 5 px; 边框:2px实体#ccc; } < a href = " # " > < / >按钮

There is the solution if you need only outline without border. It's not mine. I got if from Bootstrap css file. If you specify outline: 1px auto certain_color, you'll get thin outer line around div of certain color. In this case the specified width has no matter, even if you specify 10 px width, anyway it will be thin line. The key word in mentioned rule is "auto". If you need outline with rounded corners and certain width, you may add css rule on border with needed width and same color. It makes outline thicker.

clip-path: circle(100px at center);

这实际上是一个可点击的圆,而边界半径仍然是一个正方形,但看起来像圆。

outline样式:auto已经拥有完全的浏览器支持很久了。

速记是:

outline: auto blue;

这让你设置自定义颜色,但不是自定义厚度,不幸的是(尽管我认为浏览器的默认厚度是一个很好的默认)。

您还可以在使用outline-style: auto时设置自定义outline-offset。

outline: auto blue;
outline-offset: 0px;

通过设置outline-style: auto,我们可能很快就会看到我们的愿望

2030年见。