A simple option is to use a flexbox for section-header
- then you can:
- set the space between the h2 and the lines using a
margin
set to the h2
- set the
width
of the pseudo elements as 100% - being a flex item, it will adapt to the space available
See demo below:
.section-header {
position: relative;
display: flex; /* sets a flex container */
align-items: center; /* aligns vertically */
}
.section-header h2 {
border: 2px solid rgba(0, 0, 0, 0.1);
padding: 0.3em 0.8em;
display: inline-block;
margin: 0 1em; /* space between h2 and line if needed */
}
.section-header::before,
.section-header::after {
border-top: 1px solid black;
display: block;
height: 1px;
content: " ";
width: 100%; /* full-width ;)*/
top: 1.2em;
opacity: 0.1;
}
.text-center {
text-align: center !important;
}