If you can use flex-box, it is very simple.
p.divider { display: flex; flex-direction: row; align-items: center; } p.divider * { flex-shrink: 0 } p.divider span.divider { width: 100%; flex-shrink: 1; border-bottom: 1px solid black; margin: 5px }
<p class="divider"> <span>Part1</span> <span class="divider"></span> <span>part2</span> </p>
Here's the logic:

span.divider set to fill 100% of the width, but since this is a flexible box layout, the line cannot overflow (unless specified). When we tell the layout that none of the elements can be compressed:
p.divider * { flex-shrink: 0 }
Then set span.divider as the only element that can be compressed, it will be compressed to fit all the other elements on the line.
If you cannot use flex, you can still achieve the effect.
p.divider { background: linear-gradient(transparent 45%, black 45%, black 55%, transparent 55%); overflow: hidden; } p.divider > * { background: white; padding: 0 5px; } p.divider > .right { float: right; }
<p class="divider"> <span>Hola!!</span> <span class="right">Hola2!!</span> </p>
Explanation:

You set the p.divider background p.divider linear gradient of the desired color, and then set its children to a solid color to hide it where the content is. (You can also use an image for the background)
What are the disadvantages of this? If you have a background image, it looks bad:

Unlike a flexible layout:

source share