I am facing an issue with the placement of a before and after pseudo element for articleSubTitle
. The problem occurs when the text from articleSubTitle
wraps to a new line within a small container or on mobile devices. This causes the after
element to appear right after the last word (refer to snippet).
My goal is to have the articleSubTitle
treated as a single entity, with the before and after elements always positioned in the center of it, regardless of its length. I would share an image to illustrate, but the uploader isn't working.
I have tried using both display:block
and display:inline-block
for articleSubTitle
, but neither has resolved the issue.
Can anyone offer guidance on how I can achieve this?
.container {
width: 70%;
background: gray;
}
.articleSubTitle {
font-family: 'Nunito', sans-serif;
font-size: 1.3rem;
color: #4d4d4d;
}
.articleSubTitle:before,
.articleSubTitle:after {
content: '';
display: inline-block;
vertical-align: middle;
width: 70px;
height: 1px;
background: #2f2f2f;
}
.articleSubTitle:before {
margin-right: 10px;
}
.articleSubTitle:after {
margin-left: 10px;
}
<div class="container">
<h4 class="articleSubTitle center">From the company A & the company B</h4>
</div>