Given the following example...
/* Custom reset */
html {
margin: 20px 0;
}
body {
margin: 0 50px;
}
h1 {
margin: 0;
}
/* Problem code */
h1 {
background-color: lightblue;
text-align: center;
text-transform: uppercase;
display: flex;
align-items: center;
}
h1::before,
h1::after {
background-color: purple;
content: "";
display: inline-block;
flex: 1 0 auto;
height: 3px;
}
h1::before {
margin-left: -50px;
}
h1::after {
margin-right: -50px;
}
h1>span {
background-color: lightpink;
flex: 0 1 auto;
padding: 0 20px;
}
<h1>
<span>Fooooooooooo & Baaaaaaaaaar</span>
</h1>
When you run the snippet you'll notice a pink box with wrapped text (because it doesn't fit all in one line) and purple lines on the sides, like this:
And this is how it looks when the text doesn't wrap (which is OK and it's what I want):
In the first image there's too much space between the text and the purple lines and I need it to be only 20px, like the second image.
In other "words", I'm looking to achieve this:
(simulated image)
It goes without saying that I need this to work with dynamic content (the text could be anything, have any number of words, short or long). I also need the text to be in a single line if it fits, otherwise multiline and always with 20px
max between the purple lines and the text.