开发者

margin-bottom question,is this IE's BUG?

code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<style>
#boxTop{
    margin-bottom:20px;
    border:1px solid green;
}
#box1{
    float:left;
    border:1px solid blue;
}
#box2{
    clear:both;
    border:1px solid red;
}
</style>
</HEAD>
<BODY>
<div id="boxTop">test</div>
<div id="box1">test</div>
<div id="box2">bottom</div>
</BODY>
</HTML>

check it here

in IE,why has a padding in #box1 and #box2 ? how to fix it?

开发者_运维知识库

margin-bottom question,is this IE's BUG?


What you've come across is the IE hasLayout "feature".

Getting #box2 to have layout will fix this issue. If you are concerned with IE7, add min-height: 0; to the style for #box2, like so: http://jsfiddle.net/VTmes/


UPDATE:

There also seems to be a big with the first element on the page having a margin. I tried to remove the margin-bottom and add a margin-top to the box1 and it works. Have a look here: http://jsbin.com/uqide3/6

ORIGINAL ANSWER:

Different browsers have different default margins and paddings. Reset this at the top of your CSS and you should not have these differences.

The simplest but not very efficient reset is:

* { margin:0; padding:0 } /* '*' affects everything (all elements) */

One I've been using recently is:

html,body,h1,h2,h3,h4,h5,p,ul,li,form,button,div { margin:0; padding:0 }

Google 'CSS Reset' and you should see many variations, some claiming to be better than others. My take is use the minimum that works for you.

One other approach is to not use one at all, and just set the properties you need as you polish your design. Read this for a deatailed explanation: http://snook.ca/archives/html_and_css/no_css_reset/


float:left

property seems to be problem in IE. Even though we set margin and padding to 0, still rendering is not as expected in IE. Try to use span instead of possible in place of 2nd div and remove float:left property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜