I'm trying to style half of an <hr>
to be different from the other half, like this:
As you can see, the left half of the <hr>
is red and a bit thicker than the thin, grey side on the right. Possible to accomplish this with CSS? Thanks!
Answer: Use the CSS background-color Property You can simply use the CSS background-color property in combination with the height and border to the change the default color an <hr> element.
To create a style rule, you specify a selector, followed by { } curly brackets, and inside those curly brackets you put a list of css properties and values, each ending with a ; semicolon. This style rule selects every <p> tag and lists three properties and their values.
The thickness of the hr tag can be set using the height property in CSS. The minimum height can be 1px since the smallest unit available is 1 pixel. Images can be added to make the hr tag more beautiful in appearance. It is an empty tag, and it does not require an end tag.
For the <hr>
line you can use the css :before
pseudo-element to make the differently-colored area (please change colors and sizes to match your design):
hr {
background-color: #555;
border: none;
display: block;
height: 4px;
overflow: visible;
position: relative;
width: 100%;
}
hr:before {
background-color: #f90;
content: '';
display: block;
height: 8px;
left: 0;
position: absolute;
top: -2px;
width: 20%;
z-index: 1;
}
<hr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With