When you give width to the line, the text-align: centre
doesn't work how do I solve this?
.line-center {
margin: 0;
padding: 0 10px;
background: #fff;
display: inline-block;
}
h2 {
text-align: center;
position: relative;
z-index: 2;
width: 200px;
}
h2:after {
content: "";
position: absolute;
top: 50%;
left: 0;
right: 0;
border-top: solid 1px red;
z-index: -1;
}
<h2><span class="line-center">Test</span></h2>