When it comes to using CSS and HTML to add lines on either side of text, most solutions fill the entire width of the container. However, I am looking for a method that creates lines only 150px in length on either side of the text, like this:
https://i.sstatic.net/4pZkk.jpg
The challenge is that the text is dynamic and can vary in length, so it needs to be centered.
I have been experimenting with some code on jsfiddle:
https://jsfiddle.net/vh0j4q1e/
<div id="container">
TEXT HEADING
#container {
width:800px;
text-align:center;
background-color:#ccc;
}
h1 {
position: relative;
font-size: 30px;
z-index: 1;
overflow: hidden;
text-align: center;
}
h1:before, h1:after {
position: absolute;
top: 51%;
overflow: hidden;
width: 50%;
height: 3px;
content: '';
background-color: red;
}
h1:before {
margin-left: -50%;
text-align: right;
}
Can anyone provide suggestions on improving this code to achieve the desired outcome shown in the image above?