CSS 为 div 添加底部边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1969236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add a bottom border to a div
提问by ScG
I am trying to add a bottom border to a div
我正在尝试向 div 添加底部边框
.divLast
{
top: 0px;
margin:0px;
padding: 0px 2px 2px 3px;
border-width: 2px;
border-bottom-width:2px;
border-bottom-color:White;
width: 100%;
}
However the bottom border does not appear white. Any idea?
但是,底部边框不会显示为白色。任何的想法?
回答by rahul
You have to specify the border-bottom-stylealso to the div
您还必须为 div指定border-bottom-style
and your code becomes
你的代码变成
.divLast
{
top: 0px;
margin:0px;
padding: 0px 2px 2px 3px;
border-width: 2px;
border-bottom-width:2px;
border-bottom-color:White;
border-bottom-style: solid;
width: 100%;
}
or you can use a shorthand for the border-bottomlike below
或者您可以使用如下所示的边框底部的速记
<style>
.divLast
{
top: 0px;
margin:0px;
padding: 0px 2px 2px 3px;
border-width: 2px;
border-bottom: 2px white solid;
width: 100%;
}
</style>
<div class='divLast'>
test element with white border bottom
</div>
This works fine for me
这对我来说很好用
回答by Jamie Dixon
It's because you need to state what the border style is. Without this the border wont show:
这是因为您需要说明边框样式是什么。没有这个边界不会显示:
border-bottom-style:solid;
You could also combine your declerations into one like so:
您还可以将您的声明合并为一个,如下所示:
border-bottom:2px solid White;