Home > Web Front-end > CSS Tutorial > How Do I Change the Color of an HTML Horizontal Rule () Using CSS?

How Do I Change the Color of an HTML Horizontal Rule () Using CSS?

DDD
Release: 2024-12-03 11:16:10
Original
748 people have browsed it

How Do I Change the Color of an HTML Horizontal Rule () Using CSS?

Styling the Horizontal Rule

While the code snippet included below initially tries to change the color of an

<hr> tag using CSS, it proves unsuccessful:
<hr>
Copy after login
hr {
  color: #123455;
}
Copy after login

Solution

To alter the

<hr> element's line color, consider using the property border-color instead of color:
hr {
  border-color: #123455;
}
Copy after login

However, note that if the line size changes, the border width remains as specified in the style, while the line itself reverts to the default color. Therefore, it's advisable to also specify background-color.

The HTML 5 Boilerplate default stylesheet includes the following rule:

hr {
  display: block;
  height: 1px;
  border: 0;
  border-top: 1px solid #ccc;
  margin: 1em 0;
  padding: 0;
}
Copy after login

Additionally, an article by SitePoint highlights that

<hr> can inherit its border color from its parent element using the CSS property border-color: inherit.

The above is the detailed content of How Do I Change the Color of an HTML Horizontal Rule () Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template