我想用CSS改变我的hr标签的颜色。我尝试了下面的代码似乎不工作:

hr {
    color: #123455;
}

我认为你应该使用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}。


hr {
  background-color: #123455;
}

背景是你应该尝试改变的。

你也可以使用边界的颜色。我不确定;我认为这存在跨浏览器的问题。您应该在不同的浏览器中测试它。


hr {
  color: #f00;
  background-color: #f00;
  height: 5px;
}

有些浏览器使用color属性,有些使用background-color属性。为了安全起见:

hr {
  color: #color;
  background-color: #color;
}

在Firefox, Opera, Internet Explorer, Chrome和Safari中测试。

hr {
    border-top: 1px solid red;
}

看小提琴。


如果你使用CSS类,那么它将被所有的'hr'标签,但如果你想要一个特定的'hr'使用下面的代码,即内联CSS

<hr style="color:#99CC99" />

如果它不工作在chrome尝试以下代码:

<hr color="red" />

我认为这很有用。这是一个简单的CSS选择器。

Hr {background-color:红色;身高:1 px;边界:0;} <人力资源>


border-color适用于Chrome和Safari浏览器。 background-color适用于Firefox和Opera。 颜色工作在IE7+。


只有带颜色的border-top才能使线条有不同的颜色。

人力资源{ Border-top: 1px实心#ccc; } <人力资源>


你可以使用CSS来创建一条不同颜色的线,示例如下:

border-left: 1px solid rgb(216, 216, 216);
border-right: medium none;
border-width: medium medium medium 2px;
border-style: none none none solid;
border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(216, 216, 216);

该代码将显示垂直的灰线。


这将保持水平规则1px厚,同时改变它的颜色:

hr {
  height: 0; 
  border: 0; 
  border-top: 1px solid #083972; 
}

因为我没有声誉来评论,我将在这里给出一些想法。

如果你想要一个可变高度的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/


hr {
    height: 1px;
    color: #123455;
    background-color: #123455;
    border: none;
}

这样做可以让你在需要的时候改变高度。祝你好运。来源:如何用CSS样式HR


你应该设置border-width为0;它在火狐和Chrome浏览器上运行良好。

人力资源{ 明确:; 颜色:红色; 背景颜色:红色; 身高:1 px; 边框宽度:0; } <人力资源/ > 这是一个测试 <人力资源/ >


好吧,我是新的HTML, CSS和Java,但我尝试了我的方式,这对我在所有浏览器。我使用JS而不是CSS,它不适用于一些浏览器。

首先,我给HR元素赋予id="myHR",并在Java Script中使用。 以下是守则。

x = document.getElementById("myHR");
y = x.style.width = "600px";
y = x.style.color = "white";
y = x.style.height = "2px";
y = x.style.border = "none";
y = x.style.backgroundColor = "lightgrey";

代码适用于旧的IE 尝试了很多颜色 <人力资源颜色=“黑色”> <人力资源颜色= "蓝色" >


我在2015年5月的IE, Firefox和Chrome上进行测试,这在当前版本中效果最好。它将HR居中,并使其70%宽:

人力资源。光{ 宽度:70%; 保证金:0汽车; 边框:0px无白色; Border-top:1px纯浅灰色; } <hr class="light" />


你可以给<hr noshade>标签,然后到你的css文件中添加:

人力资源{ border-top: 0; 颜色:# 123455; } <hr noshade /> 这是个测试 <hr noshade />


使用字体颜色修改水平规则使它们更加灵活和易于使用。

color属性在默认情况下是不继承的,因此需要将以下属性添加到hr's中以允许颜色继承:

/*允许hr继承颜色*/ Hr{边框:1px solid;} /*可重复使用的颜色修饰符*/ .fc_-alpha{颜色:深红色;} 正常的人力资源: <人力资源> Hr与<span class="fc_-alpha">颜色修饰符</span>: <人力资源类= " fc_-alpha " >


你可以这样做:

人力资源{ 边框:1px纯红色; } <人力资源/ > 这是个测试 <人力资源/ >


在阅读了这里所有的答案,并看到了所描述的复杂性之后,我开始了一个关于人力资源实验的小转移。并且,结论是你可以扔掉你写的大部分monkeypatched CSS,阅读这篇小入门,只使用这两行纯CSS:

hr {
  border-style: solid;
  border-color: cornflowerblue; /* or whatever */
}

这就是你为人事简历设计风格所需要的全部内容。

适用于跨浏览器、跨设备、跨操作系统、跨英语频道、跨年龄。 没有“我认为这可以工作……”,“你需要记住Safari/IE……”等等。 没有额外的CSS -没有高度,宽度,背景颜色,颜色等涉及。

只有防弹的彩色hr。就是这么简单。


奖励:给HR一些高度H,只要设置边界宽度为H/2。


我认为这是最有效的方法:

<hr style="border-top: 1px solid #ccc; background: transparent;">

或者如果你喜欢在所有的hr元素上写这个CSS:

hr {
  background-color: transparent;
  border-top: 1px solid #ccc;
}

它很简单,也是我的最爱。

<hr style="background-color: #dd3333" />

一般来说,你不能像设置其他颜色一样,用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" />

希望这能有所帮助。


我两边都打了个赌:

hr {
  border-top: 1px solid purple;
  border-color: purple;
  background-color: purple;
  color: purple;
}

你可以像这样添加引导bg类

<hr class="bg-light" />

我喜欢设置边界顶部的答案,但他们不知何故仍然有点离开Chrome… 但是如果我设置border-top: 1px纯黑色;And border-bottom: 0px;我最终得到了一条真正的单线(这也适用于更高的厚度)。