Add background color to text but not the entire line

Hi there,

I’m trying to add a background color to an H4 tag in order to create a sort of inverted text result.
It is working except for the fact that the background color extends to the whole line, whereas I’d like to have the bg color ending where the text ends.

This is code I’m using:

h4 {
    color: white;
    background-color: black;

A is the effect I’m trying to achieve, B is what I get right now:

Not much context to go on, so, start with this and see if anything “breaks”.

h4 {display:inline-block;}

Spot on!
It worked like a charm, thank you, ronpat!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.