-3

Why six blanks and five blanks result in same effect?

<html>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hello<br/>hello<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hello<br/>hello<br/>
</html>

To open it with firefox.

enter image description here

  1. The are different effect.

2.still problem for

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hello<br/>hello<br/>

There are five blanks here ,why only three blanks displayed on the web page?

enter image description here

showkey
  • 482
  • 42
  • 140
  • 295

5 Answers5

16

It clearly shows its not the same effect. enter image description here

Peter Aron Zentai
  • 11,482
  • 5
  • 41
  • 71
4

One &nbsp is one extra space before your content. So it cannot show the same result. You can use pure css for that matter.

<html>
<body>
    <div style='padding-left:0px;'>Hello</div>
    <div style='padding-left:50px;'>Hello</div>
    <div style='padding-left:25px;'>Hello</div>
    <div style='padding-left:0px;'>Hello</div>
</body>
</html>

Output:

enter image description here

Cheers!

incalite
  • 3,077
  • 3
  • 26
  • 32
3

Using &nbsp; is not a good approach. Instead use css padding to achieve the required effect.

undo
  • 257
  • 3
  • 19
Rovi
  • 259
  • 1
  • 3
2

The effect is not clearly the same. But I think what @it_is_a_literature meant was why is the "h" in first line starting from the second "l" from the second line. My answer to it is that, not every character has a equal width or dimensions. For eg. the "l" in hello takes less space than "e" in the same word.

The " " works like a space bar. So there are 5 spaces not 3.

K.Shrestha
  • 567
  • 3
  • 8
  • To PeterAronZentai's point, you can use the `` tag to get monospaced output (but that's not what you want here; use padding as others suggest). – Autumn Leonard Jan 12 '16 at 22:37
1

Main font families haven't a regular size for each character (eg. : 'l' is thinner than 'L'). In other words, 5 spaces takes small place than 5 characters in "hello".

If you need regular character spacing (making ASCII art ?), you should use monospace font family like Courrier or Lucida Console with a CSS class like so :

.monospace { font-family: "Courier New", Courier, monospace; }

Here is a Plunker sample to see the differences.

kewwwa
  • 137
  • 4