div和带有边界半径的边界之间的透明空间 [英] Transparent space between div and border with a border radius
问题描述
我正在尝试获得这样的东西:
I am trying to get something like this:
我尝试使用轮廓,但是无法在轮廓上设置边框半径.我还尝试了带有白色边框的盒子阴影,但是我需要边框是透明的.任何想法将不胜感激.
I've tried using outline but I can't set the border radius on an outline. I've also tried a box shadow with a white border but I need the border to be transparent. Any ideas would be greatly appreciated.
无法使用此设置轮廓的边界半径:
can't set border radius of the outline with this:
.btn {
outline: 1px solid #B54104;
outline-offset: 1px;
}
轮廓和按钮之间的间隙不透明:
gap between outline and button is not transparent:
.btn {
border: 1px solid #fff;
box-shadow: 0 0 0 1px #c5170a;
}
按钮和偏移轮廓之间的间隙必须为透明.
The gap between the button and the offset outline must be transparent.
推荐答案
You can try a background coloration relying on background-clip
to avoid coloring a part of the button:
.button {
display:inline-block;
padding:3px; /*control the spacing*/
width:100px;
text-align:center;
line-height:30px;
border-radius:15px;
color:#fff;
border:2px solid orange;
background: orange content-box; /*color only the content*/
}
body {
background:pink;
}
<div class="button">
button
</div>
使用padding-box
并控制带有边框的空间的相同想法:
Same idea using padding-box
and controling the space with border:
.button {
display:inline-block;
width:100px;
text-align:center;
line-height:30px;
border-radius:15px;
color:#fff;
border:5px solid transparent; /*control the spacing*/
background: orange padding-box; /*don't color the border*/
box-shadow: 0 0 0 2px orange;
}
body {
background:pink;
}
<div class="button">
button
</div>
这篇关于div和带有边界半径的边界之间的透明空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!