Sometimes, we want to set a background color for the width of the text, but not the width of the entire element, using CSS.
In this article, we’ll look at how to set a background color for the width of the text, but not the width of the entire element, using CSS.
How to set a background color for the width of the text, but not the width of the entire element, using CSS?
To set a background color for the width of the text, but not the width of the entire element, using CSS, we put our text in an element.
For instance, we write
<h1><span>The Last Will and Testament of Eric Jones</span></h1>
to put text in a span.
Then we write
h1 {
text-align: center;
}
h1 span {
background-color: green;
}
to set the background-color
of the span to green
.
Conclusion
To set a background color for the width of the text, but not the width of the entire element, using CSS, we put our text in an element.