Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "Invisible space" from HTML [duplicate]

Tags:

html

css

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?

like image 856
Icemanind Avatar asked Aug 29 '12 17:08

Icemanind


People also ask

How do I get rid of unwanted space in HTML?

Approach 1: We can remove space between any two tags by simply using margin-bottom property. The margin-bottom property sets the bottom margin of an element. We will assign a negative value to the margin-bottom of a particular tag to eliminate the extra space between the tags as shown.

How do I remove spaces between characters in HTML?

Use a negative letter-spacing margin-left on it in order to remove it.


2 Answers

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 }
like image 184
Zoltan Toth Avatar answered Sep 19 '22 13:09

Zoltan Toth


This is caused by line breaks. You have two choices:

  1. Remove the line breaks
  2. 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>
like image 35
James Hill Avatar answered Sep 20 '22 13:09

James Hill