tags:

views:

728

answers:

3

EDIT From what I've found there is no way to remove the margin... except if you either have everything on the same line or, add comments to comment out the line breaks. example:

<div>Some Text</div><!--
--><div>Some Text</div>

not the best solution but still easier to read if you have multiple lines...

-mike

Hello!

I'm working with a few div's that are set to display: inline-block and have a set height and width - In the html if there is a line break after each div there is an automatic 5px margin add to the right and bottom of the div.

example:

<div>Some Text</div>
<div>Some Text</div>

Is there a property that I've overlooked that will allow me to reset the automatic margin?

Thanks!

+1  A: 

Can you post a link to the HTML in question?

Ultimately you should be able to do:

div {
    margin:0;
    padding: 0;
}

to remove the spacing. Is this just in one particular browser or all of them?

Jeepstone
no link to it right now... but yeah, i have a reset(*) that sets margin and padding to 0. Seems to be a cross browser issue. Not one browser does it correctly.... If i put the divs on the same line it margin disappears. I can do it that way but i'm extremely anal about clean html! and... I sometimes use inline-block for my ul navigations and i can never get that margin to disappear. thanks;)
mike
update... with all of them(8 divs 2 rows of 4) on the same line, the bottom margin is ignored.... its super strange. code looks like:* { margin: 0; padding: 0; }div { margin: 0 10px 10px 0; }<div>Some Text</div><div>Some Text</div>
mike
What DOCTYPE are you using?
Jeepstone
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
mike
A: 

For the record, that margin and padding resetting didn't do the trick for me, but this quote from one of the comments above turned out to be crucial and solved the issue for me: "If i put the divs on the same line it margin disappears."

Enchilada
I'm not sure how I marked this as the answer because it did not work for me....
mike
+2  A: 

The divs are treated as inline-elements. Just as a space or line-break between two spans would create a gap, it does between inline-blocks. You could either give them a negative margin or set word-spacing of a surrounding container to -1em.

Daniel
wow.. I never even thought to give it negative spacing!
mike
Setting word-spacing to 0 worked for me. The only frustrating thing is that word-spacing is inherited, so it has to be explicitly redefined for child elements.
Josiah Sprague