Here is an idea using flexbox. The trick is to make the span an inline-flex
container with a column direction so we keep the pseudo-element in-flow; thus it will affect the width of the container.
The widest one between the current content and the pseudo element will define the width.
p {
margin-top: 50px;
}
span.chunk {
position: relative;
display: inline-flex;
flex-direction: column;
vertical-align: bottom; /*This is mandatory to keep the text without chunk in the bottom*/
}
span.chunk:before {
content: attr(data-chord);
position: relative;
}
<p>
As
<span class="chunk" data-chord="CCC">I was going over the</span>
<span class="chunk" data-chord="Am a long text">f</span>
more text here
<span class="chunk" data-chord="BB">ar</span>
</p>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…