CSS 属性边框颜色不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14156674/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:10:46  来源:igfitidea点击:

CSS Property Border-Color Not Working

cssborder

提问by Zeb-ur-Rehman

I have issue with border-color. It didn't work. I'm new to css here is the fiddle. http://jsfiddle.net/zeburrehman/aFzKy/151/

我有边框颜色的问题。它没有用。我是 css 新手,这里是小提琴。 http://jsfiddle.net/zeburrehman/aFzKy/151/

<div id="box">
Hello! The color of box border should be red!!
</div>?

#box {
border-color: red;
}?

回答by Ashwin

By default the border-widthis 0and border-styleis none

默认情况下border-width0border-stylenone

So you need to set them to border-width:1pxand border-style:solid. You can combine all the border properties into one as below:

所以你需要将它们设置为border-width:1pxborder-style:solid。您可以将所有边框属性合并为一个,如下所示:

#box {
    border:1px solid red
}

回答by Shaun

I had an issue where it seemed that border-colorwas not being respected, confusingly it even showed having the right color in the style inspector in Chrome (possibly a Chrome bug). The key thing for me was that if the shorthand border style is specified, it sets all three aspects of the border style, regardless of if they are included or not so:

我有一个问题,似乎border-color没有得到尊重,令人困惑的是,它甚至在 Chrome 的样式检查器中显示了正确的颜色(可能是 Chrome 错误)。对我来说,关键是如果指定了速记边框样式,它会设置边框样式的所有三个方面,无论是否包含它们:

border-left: 1px;

Actually overwrites both the border-left-styleand border-left-colorproperties even though they weren't included. This can for example cause an inherited style to be overridden and appear not to work.

实际上覆盖了border-left-styleborder-left-color属性,即使它们没有被包含在内。例如,这可能导致继承的样式被覆盖并且看起来不起作用。

回答by RJo

You need to add the border style:

您需要添加边框样式:

#box {
    border: 1px solid red;
}

回答by Tanky

Try this : border: 5px solid red;

试试这个:边框:5px纯红色;

回答by Hunter

You can use hex color code for red as well, which is #ff0000(RGB). 100% Red, 0% Green and 0% Blue if you want pure red color.

您也可以将十六进制颜色代码用于红色,即#ff0000(RGB)。如果您想要纯红色,则为 100% 红色、0% 绿色和 0% 蓝色。

#box {
   border: 2px solid #ff0000;
}

回答by IsMaTh IM

#box{
    border:3px solid #aacfac;
    }

I hope this helps!

我希望这有帮助!