【发布时间】:2015-07-26 03:07:39
【问题描述】:
如何获得一些空间的边框?就像-
【问题讨论】:
标签: css
如何获得一些空间的边框?就像-
【问题讨论】:
标签: css
使用大纲属性:
outline: 2px solid red;
outline-offset: 3px;
【讨论】:
如果没有边框,仅轮廓是不够的。
但您可以设置边框以匹配您的相应背景颜色:
#test{
background: red;
border: 2px solid white;
outline: 2px solid red;
}
https://jsfiddle.net/dntbn733/
对于圆角,您可以包装一些 div 来实现相同的效果:
.red{
background-color:red;
padding:2px;
border-radius:10px;
}
.white {
background-color:white;
padding:2px;
border-radius:10px;
}
<div class="red">
<div class="white">
<div class="red">
test
</div>
</div>
</div>
【讨论】:
您可以通过简单地使用 CSS :before 或 :after 选择器来实现这一点。
#borderer {
background: red;
border: 10px solid white;
border-radius: 50%;
width: 140px;
height: 140px;
line-height: 140px;
text-align: center;
vertical-align: middle;
font-size: 88px;
font-weight: bold;
font-family: calibri;
position: relative;
margin: 50px auto;
}
#borderer:after {
width: 170px;
height: 170px;
position: absolute;
background: red;
border-radius: 50%;
content: '';
left: -15px;
top: -15px;
z-index: -1;
}
<div id="borderer">
2
</div>
【讨论】: