user3118602
user3118602

Reputation: 593

Enforcing background-color to text only

I would like to ask how can I give my text ONLY with the background-color property and not the spacing using CSS or HTML or both.

For example,

Hello everyone!

I only want the background-color to show on Hello and everyone! and not the entire length of Hello everyone!

I have tried searching in the Internet but I can't find any solution.

Thanks!

Upvotes: 1

Views: 104

Answers (3)

Jon Taylor
Jon Taylor

Reputation: 7905

Wrap each word in a span element and give the span elements background colours.

Upvotes: 2

keeehlan
keeehlan

Reputation: 8054

There's a lot of different ways to do this, but for a beginner I'd recommend wrapping all text with <span>.

Here's a fiddle.

Upvotes: 0

Oriol
Oriol

Reputation: 288710

Try placing your text inside a wrapper, and style it with

display: inline;
background-color: whatever;

Note that if you use a wrapper which is inline by default (e.g. <span>), you don't need display: inline.

Upvotes: 0

Related Questions