I would like to have a centered line next to my headline to the left and the right. I found a lot of solutions for a centered text, but not for a left aligned.
Is there a solution not using extra boxes and flex-grow?
The line should take the rest of the h2
element.
h2 {
background-color: yellow;
}
h2:before {
content: "";
width: 2em;
margin-right: 0.5em;
display: inline-block;
vertical-align: middle;
border-bottom: 1px solid;
}
h2:after {
content: "";
/** How to calculate to 100% */
width: 50%;
margin-left: 0.5em;
display: inline-block;
vertical-align: middle;
border-bottom: 1px solid;
}
<h2>Title</h2>
<h2>A long long Title</h2>