frequent
frequent

Reputation: 28513

Can a   have a CSS font-size?

I'm running a script that adds

 

To a tag in case my script does not return any text to fill a button element.

Problem is, although the span has its space, the height of the elemeny is wrong.

Question
Is there a way to give font-size to a nbsp;? After all, it's a space, so it should respect the font-size being set on an element?

Upvotes: 3

Views: 9264

Answers (3)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201668

A no-break space, which can be represented in HTML as &nbsp;, is treated the same way as a printable character, just with an empty glyph. This means that font size affects it, and font size can be set on it like on any printable character. If you wish to make its font size differ from the font size of adjacent characters, then you need to wrap it in an element, e.g. <span class=nobr>&nbsp;</span>, and set font-size on it.

If a no-break space is the sole content of a button element, e.g. <button ...>&nbsp;</button>, then you can simply set font-size on that element. Note that the size of the button also depends on the line-height of its content as well as the rendering algorithm of buttons in the browser (which make the button larger than the size of its content).

Your real problem is probably very different and best addressed in a completely different way, but for the record, this was an answer to the question as asked.

Upvotes: 5

yes. empty space is also considered text and it will resize the button it fills in. check this demo

html

<button class="button1">&nbsp;

css

.button1
{
    font-size: 22px;
}

Upvotes: 0

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382194

There's no need to put something into a button to give it a size.

Here's how you can give a button a 20x20 size :

HTML :

 <button id=a></button>

CSS :

#a {
  weight:20px;
  height:20px;
}

Demonstration

Upvotes: 2

Related Questions