0

Here's my problem: http://jsfiddle.net/gregseth/548S2/

Why is there a white space between the elements? And how can I get rid of it?

In addition why are the dimensions of the <img> not taken into account on jsfiddle, when it is on a 'normal' HTML page (Firefox)?

2
  • 1
    Hint: jsfiddle.net/548S2/1 Commented Jun 8, 2012 at 9:44
  • display:inline-block is causing problem
    – user1432124
    Commented Jun 8, 2012 at 9:44

4 Answers 4

2

This is a result of HTML rendering a space when block items have a space or line break between them. You can either float the items to the left:

http://jsfiddle.net/548S2/4/

or remove the line breaks between the elements:

http://jsfiddle.net/548S2/2/

1

It's because of the

nav a { display:inline-block; }

If you'd change this to:

nav a {    
    display:block;
    float:left;
}

the margins are gone.

jsfiddle: http://jsfiddle.net/548S2/3/

1
  • In this simplified case, a float will work fine but it may be more complex when you try this on a full website. See my answer below for details.
    – cronoklee
    Commented Jun 8, 2012 at 10:00
0

Just apply float:left to the "nav a" in CSS.

-1

It's the spaces (the line breaks) between the <a> elements in your html. This happens on all inline or inline-block elements.

OPTION 1: Use margin-right:-4px; on the <a> tags.

OPTION 2: Remove the spaces between the <a> tags.

OPTION 3: Change the <a> tags to display:block; float:left as described in other answers. In this case, you need to fix the height of the container element (<nav> in your case), or use a clear:left on the next element to prevent the floats overlapping it. Sometimes it's useful to avoid this floating approach and use one of the other options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.