12

Possible Duplicate:
A Space between Inline-Block List Items

I have a JSFiddle demo of my html code. Here is the code here:

<span style="display: inline">Hello Wo</span>
<span style="display: none;"></span>
<span style="display: inline">rld</span>​

The problem I'm having is that an extra space is being inserted between the 'o' and the 'r' in Hello World!. The display style is set to none, so can someone please tell me how I can get the Hello World! phrase without the space?

Community
  • 1
  • 1
Icemanind
  • 47,519
  • 50
  • 171
  • 296

3 Answers3

27

The linebreaks are causing it - http://jsfiddle.net/RhvjF/1/

Can't find the particular post, but smart people suggested 3 ways of fixing it:

  1. Put everything in one line (remove all line breaks)
  2. Comment out the line breaks, like

    <span style="display: inline">Hello Wo</span><!--
    --><span style="display: none;"></span><!--
    --><span style="display: inline">rld</span>
    
  3. Set the container font-size to 0 and re-set it for span-s

UPDATE

There are at least 2 more ways:

  1. Break the tags, like

    <span style="display: inline">Hello Wo</span
    ><span style="display: none;"></span
    ><span style="display: inline">rld</span>
    
  2. Float the elements, i.e. span { float: left }
Icemanind
  • 47,519
  • 50
  • 171
  • 296
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
  • For completeness, the other way is to break the lines inside the tags, as per the second example on this page from the HTML5 spec: http://dev.w3.org/html5/spec/the-section-element.html#the-section-element – Alohci Aug 29 '12 at 17:42
  • 3
    Personally, I'm not a fan of solutions #2 or #(4). It makes the markup less readable. – Shmiddty Aug 29 '12 at 17:53
  • @Shmiddty they are verbose indeed, but they exist and someone might find them useful, so it wouldn't be fair to exclude solutions based on personal preferences :) – Zoltan Toth Aug 29 '12 at 17:55
  • 1
    @ZoltanToth But, think of the children! Someone else will be handling this code at some point, surely. – Shmiddty Aug 29 '12 at 17:57
  • @Shmiddty Children should read the comments too and there they'll find your warning – Zoltan Toth Aug 29 '12 at 18:01