Html 如何更改 <hr> 标签的粗细和颜色?

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

How to change the thickness & colour of the <hr> tag?

htmlcsscolorsthickness

提问by Jamie Bohanna

I can see this has been answered but i've tried all of the solutions yet still have a barely visable HR.

我可以看到这已经得到了回答,但我已经尝试了所有解决方案,但仍然几乎看不到 HR。

What am I doing wrong?

我究竟做错了什么?

hr {
    background-color: dimgrey;
    color: dimgrey;
    border: solid 2px dimgrey;
    height: 5px;
    width: 1000px;
}

回答by mmccaff

Not sure what you consider barely visible but a 5px height is pretty visible. :)

不确定你认为几乎不可见的东西,但 5px 的高度是很明显的。:)

Make sure that you are defining this css after other css which might be overwriting this rule.

确保在其他可能覆盖此规则的 css 之后定义此 css。

Or, use !important to give this rule precedence:

或者,使用 !important 赋予此规则优先级:

hr {
    background-color: dimgrey !important;
    color: dimgrey !important;
    border: solid 2px dimgrey !important;
    height: 5px !important;
    width: 1000px !important;
}

Another approach is to define a custom class for this style:

另一种方法是为此样式定义一个自定义类:

.bigHr {
    background-color: dimgrey !important;
    color: dimgrey !important;
    border: solid 2px dimgrey !important;
    height: 5px !important;
    width: 1000px !important;
}

... and then use that class when you want this style:

...然后在需要这种样式时使用该类:

<hr class="bigHr">