我想用CSS改变我的hr标签的颜色。我尝试了下面的代码似乎不工作:
hr {
color: #123455;
}
我想用CSS改变我的hr标签的颜色。我尝试了下面的代码似乎不工作:
hr {
color: #123455;
}
当前回答
一般来说,你不能像设置其他颜色一样,用CSS设置水平线的颜色。 首先,Internet Explorer需要CSS中的颜色读起来像这样:
“颜色:# 123455”
但是Opera和Mozilla需要你的CSS中的颜色读起来像这样:
background - color: # 123455”
因此,您需要将这两个选项添加到您的CSS中。
接下来,你需要给水平线一些尺寸,否则它将默认为浏览器设置的标准高度、宽度和颜色。 下面是一个示例代码,说明了你的CSS应该是什么样的,才能得到蓝色的水平线。
hr {
border: 0;
width: 100%;
color: #123455;
background-color: #123455;
height: 5px;
}
或者当你插入一条水平线时,你可以直接在你的HTML页面中添加样式,就像这样:
<hr style="background:#123455" />
希望这能有所帮助。
其他回答
你可以像这样添加引导bg类
<hr class="bg-light" />
hr {
height: 1px;
color: #123455;
background-color: #123455;
border: none;
}
这样做可以让你在需要的时候改变高度。祝你好运。来源:如何用CSS样式HR
我认为这很有用。这是一个简单的CSS选择器。
Hr {background-color:红色;身高:1 px;边界:0;} <人力资源>
我认为你应该使用border-color而不是color,如果你的意图是改变<hr>标签产生的线条的颜色。
尽管如此,评论中已经指出,如果你改变了线条的大小,边框仍然会和你在样式中指定的一样宽,并且线条将被默认的颜色填充(这在大多数情况下不是理想的效果)。所以在这种情况下,你似乎还需要指定background-color(就像@Ibu在他的回答中建议的那样)。
HTML 5样板项目在其默认样式表中指定了以下规则:
hr { display: block; height: 1px;
border: 0; border-top: 1px solid #ccc;
margin: 1em 0; padding: 0; }
SitePoint最近发表了一篇名为“12个鲜为人知的CSS事实”的文章,提到<hr>可以将它的border-color设置为它的父颜色,如果你指定了hr {border-color: inherit}。
因为我没有声誉来评论,我将在这里给出一些想法。
如果你想要一个可变高度的CSS,去掉所有的边框,并给出一个背景色。
hr{
height:2px;
border:0px;
background:green;
margin:0px;/*sometimes useful*/
}
/*Doesn't work in ie7 and below and in Quirks Mode*/
if you want simply a style that you know that will work (example: to replace a border in a ::before element for most email clients or hr{ height:0px; border:0px; border-top:2px solid blue; margin:0px;/*useful sometimes*/ } In both ways, if you set a width, it will always have it's size. No need to set display:block; for this. To be totally safe, you can mix both, 'cause some browsers can get confused with height:0px;: hr{ height:1px; border:0px; background:blue; border-top:1px solid blue; margin:0px;/*useful sometimes*/ } With this method you can be sure that it will have at least 2px in height. It's a line more, but safety is safety. This is the method you should use to be compatible with almost everything. Remember: Gmail only detects inline css and some email clients may not support backgrounds or borders. If one fails, you will still have a 1px line. Better than nothing. In the worst cases, you can try to add color:blue;. In the worst of the worst cases, you can try to use a <font color="blue"></font> tag and put your precious <hr/> tag inside it. It will inherit the <font></font> tag color. With this method, you WILL want to do like this: <hr width="50" align="left"/>. Example: <span> awhieugfrafgtgtfhjjygfjyjg <font color="#42B3E5"><hr width="50" align="left"/></font> </span> <!--Doesn't work in ie7 and below and in Quirks Mode--> Here is a link for you to check: http://jsfiddle.net/sna2D/