How do I set a background-color for the width of text, not the width of the entire element, using CSS?
Put the text in an inline element, such as a <span>. And then apply the background color on the inline element. An inline element is as big as its contents is, so that should do it for you.