Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot eliminate space between 2 horizontal divs inside containing div

Tags:

html

css

Should be easy, right? Just set the outer containing div's padding to zero, and set the two side-by-side divs inside the outer div to have margin:0 but that's having no effect on the space between the 2 horizontal divs. What I need is the red-outlined left div to touch the green-outlined right-side div.

Despite my effort using padding and margin, the space between the 2 divs will not go away.

I have looked at many answers on SO but so far no one's broken it down to this simple example -- my fiddle shows this issue, at

http://jsfiddle.net/Shomer/tLZrm/7/

And here is the very simple code:

<div style="border: 4px solid blue; white-space:nowrap; margin:0; padding:0; width:80%">

   <div style="display:inline-block; width:45%; overflow:hidden; margin:0; border: 1px solid red"> Flimmy-flammy
    </div>

    <div style="display:inline-block; width:50%; overflow:hidden; margin:0px; border: 1px solid green"> Hambone-Sammy
    </div>

</div>
like image 923
wantTheBest Avatar asked Nov 27 '11 01:11

wantTheBest


People also ask

How do I remove horizontal space between two divs?

There are two methods for removal of space between two divs or two elements. First one is, assign the font size of the parent of the inline block element to 0px and then assign the proper font-size to the inline block element. and Second is, Make the display of the parent element to flex.

Why is there a gap between my divs?

The gap is the result of the margin of the paragraph escaping from its container.

Why is there extra space at the bottom of my div?

If you try to put an image inside a <div> element that has borders, you will see an extra white space (around 3px) at the bottom of image. It happens because image is an inline-level element so browser adds some whitespace under the baseline to adjust other inline elements.


2 Answers

The space rendered between your divs is the whitespace (represented as dots), collapsed, in:

    </div>.  
.................  
....<div>

Instead, try coding like this:

    </div><div>

and the gap will vanish.

like image 76
Juan Lanus Avatar answered Sep 25 '22 03:09

Juan Lanus


Use the float property.

Example with div { float: left; } : http://jsfiddle.net/tLZrm/10/.

like image 39
GG. Avatar answered Sep 21 '22 03:09

GG.