Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style half of my <hr>s differently from the other half?

Tags:

html

css

I'm trying to style half of an <hr> to be different from the other half, like this:

enter image description here

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!

like image 550
HappyHands31 Avatar asked Nov 04 '17 16:11

HappyHands31


People also ask

How to change a hr color?

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.

How do you write a style rule for each paragraph?

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.

How to increase thickness of hr line?

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.


1 Answers

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>
like image 186
Sergey Sklyar Avatar answered Oct 22 '22 06:10

Sergey Sklyar