oshliaer
oshliaer

Reputation: 4979

How to highlight spaces in a tag? (CSS only)

I have the tag

<span class="block" style="width:12px;height:17px">&nbsp;tttt&nbsp;ttt&nbsp;ttttt</span>

I want to highlight only &nbsp;. How can I do it using only CSS?

Upvotes: 1

Views: 2737

Answers (2)

gomzy
gomzy

Reputation: 260

Well there is no such way to select the space, but if for some reason you really want to do it then, you can try something like this:

<span class="block" style="width:12px;height:17px"><span style="background-color:#F00;">&nbsp;</span>tttt<span style="background-color:#F00;">&nbsp;</span>ttt&nbsp;ttttt</span>

Put the &nbsp; within a span like

<span style="background-color:#F00;">&nbsp;</span>

Upvotes: 3

BoltClock
BoltClock

Reputation: 723598

You can't do this with only CSS; you will need to wrap each non-breaking space in a span and give that span a background color. Wikipedia does this in their article for example:

In Unicode, it is encoded as <span class="nowrap">U+00A0</span> <span class="unicode" style="background:lightblue">&#160;</span> <span class="smallcaps" style="font-variant:small-caps;">no-break space</span>

Upvotes: 2

Related Questions