5px extra margin getting added to the bottom of each div

若如初见. 提交于 2019-11-30 11:47:35

You need to specify units on your CSS declarations.

http://jsfiddle.net/m7YCW/

div.main_nav
{ 
    display: inline-block;
    height: 25px;       /* set px */
    width: 900;
    padding: 0;
    margin: 0;
    vertical-align: bottom;    
}

Learn to make use of your developer tools in Chrome, if you had right mouse buttoned on the elements and chosen -> inspect it would bring up the dev tools. You can then view the 'metrics' and 'computed styles' areas to see that main_nav was rendering as 30px instead of 25px and also that there was a warning symbol next to the 25 css declaration and it was being explicitly dropped.

ChriWe

Ege's answer was very useful for me. I have spent hours to find the reason of a bottom padding of some images in div's. It was the line-height. Set it to 0px on the interesting areas:

.divclass {
    line-height: 0px; /* crucial for bottom padding 0 !!! */
}
Ege

I think your problem is the line-height. Yup, there it is. Just added line-height:0, on firebug and they stuck together.

The thing about inline-blocks is that they behave just like any inline text, you also have a similar issue on the navigation below, because you pressed enter in your code, it will render it as a non-breaking space and add extra x margins to the right and left sides as well. X here will depend on the font size.

In order to solve this, you can either close and open tags on the same line like below:

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

or you can set the font-size and line-height to 0, but thats not always possible if you don't have other selectors inside that div.

Try setting vertical-align:bottom on the images.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!