Why centering with margin 0 auto works with display:block but does not work with display:inline-block ?

My understanding is as follows (though I am happy to be corrected). Inline elements do not have a width property, and so the “auto” cannot be calculated. Block elements have a width property, so the width of the “auto” can be calculated. Inline-block elements have an outside which acts inline, but an inside which acts … Read more

Remove “whitespace” between div element

The cleanest way to fix this is to apply the vertical-align: top property to you CSS rules: #div1 div { width:30px;height:30px; border:blue 1px solid; display:inline-block; *display:inline;zoom:1; margin:0px;outline:none; vertical-align: top; } If you were to add content to your div‘s, then using either line-height: 0 or font-size: 0 would cause problems with your text layout. See … Read more

Set position absolute and margin

I know this isn’t a very timely answer but there is a way to solve this. You could add a “spacer” element inside the element positioned absolutely with a negative bottom margin and a height that is the same size as the negative bottom margin. HTML: <div id=”container”> <div class=”spacer”></div> </div> CSS: // same container … Read more

CSS margin-top of affects parent’s margin

Thank you all for your answers, @gaurav5430 posted a link with a very precise definition that I would like to summarize into this answer. As of why they decided that this elements should behave like this it is still unclear for me; but at least we were able to find a rule that applies to … Read more