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>
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.
The gap is the result of the margin of the paragraph escaping from its container.
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.
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.
Use the float
property.
Example with div { float: left; }
: http://jsfiddle.net/tLZrm/10/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With