如何仅在一侧设置 css 边框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15405307/
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
How can I set a css border on one side only?
提问by user782104
For a given div
I would like to only display a border on the left, right, top, or bottom side.
对于给定的div
我只想在左侧、右侧、顶部或底部显示边框。
Currently I have the following, which puts a border on all sides:
目前我有以下内容,它在所有方面都有一个边界:
#testdiv {
border: 1px solid;
}
What do I need to do in order to have a border only on the left side?
我需要做什么才能只在左侧有边框?
回答by Denys Séguret
回答by otinanai
If you want to set 4 sides separately use:
如果要分别设置 4 个边,请使用:
border-width: 1px 2em 5px 0; /* top right bottom left */
border-style: solid dotted inset double;
border-color: #f00 #0f0 #00f #ff0;
回答by Sowmya
回答by Guffa
You can specify border separately for all borders, for example:
您可以为所有边框单独指定边框,例如:
#testdiv{
border-left: 1px solid #000;
border-right: 2px solid #FF0;
}
You can also specify the look of the border, and use separate style for the top, right, bottom and left borders. for example:
您还可以指定边框的外观,并为顶部、右侧、底部和左侧边框使用单独的样式。例如:
#testdiv{
border: 1px #000;
border-style: none solid none solid;
}
回答by Gautam3164
Try like this
像这样尝试
#testdiv{
border-left:1px solid;
}
}
回答by korosmatick
#testDiv{
/* set green border independently on each side */
border-left: solid green 2px;
border-right: solid green 2px;
border-bottom: solid green 2px;
border-top: solid green 2px;
}