How to remove "Invisible space" from HTML [duplicate]
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?
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:
- Put everything in one line (remove all line breaks)
-
Comment out the line breaks, like
<span style="display: inline">Hello Wo</span><!-- --><span style="display: none;"></span><!-- --><span style="display: inline">rld</span>
Set the container
font-size
to0
and re-set it forspan
-s
UPDATE
There are at least 2 more ways:
-
Break the tags, like
<span style="display: inline">Hello Wo</span ><span style="display: none;"></span ><span style="display: inline">rld</span>
- Float the elements, i.e.
span { float: left }
This is caused by line breaks. You have two choices:
- Remove the line breaks
- Float your content.
Option 1
<span style="display: inline">Hello Wo</span><span style="display: none;"></span><span style="display:inline">rld</span>
Option 2
<style>
#spanContainer > span { float:left; }
</style>
<div id="spanContainer">
<span style="display: inline">Hello Wo</span>
<span style="display: none;"></span>
<span style="display: inline">rld</span>
</div>
See http://jsfiddle.net/RhvjF/2/
HTML:
<div id="wrapper">
<span style="display: inline">Hello Wo</span>
<span style="display: none;"></span>
<span style="display: inline">rld</span>
</div>
CSS:
#wrapper{
font-size:0;
}
#wrapper>*{
font-size:16px; /* Or whatever you want */
}