Effective Solution for Cross-Browser Compatibility
If you're looking for a workaround that is compatible with Chrome, Firefox, and Internet Explorer, this solution might be just what you need.
Check out the Example Here
The issue with compatibility in IE was caused by the positioning of pseudo elements not being relative to the text. To solve this problem, I removed absolute positioning from the pseudo elements and changed their display to table-cell
, ensuring they are positioned correctly relative to the text.
You can adjust the right
/left
positioning to customize the spacing around the text as needed.
.line {
display: table;
white-space: nowrap;
overflow: hidden;
text-align: center;
}
.line:before,
.line:after {
content: '';
display: table-cell;
position: relative;
top: 0.5em;
width: 45%;
height: 1px;
border-top: 1px solid #f00;
}
.line:before {
right: 5%;
}
.line:after {
left: 5%;
}
<h2 class="line">THE HEADING</h2>
<h2 class="line">THE LONGER HEADING</h2>