The difference between the div margin attribute and the chrome and IE

Source: Internet
Author: User

All of a sudden, the layout that looks neat under chrome becomes a mess under IE. To find out why, I changed the div's Background-color attribute. Finally, the width of the same div is found to be different under IE and chrome. This is a big night, it's really creepy!
After that, I did a test. When:

The code is as follows:

Div1
{
width:960px;
margin:0px;
padding:0px;
}

At this time, in two browsers is no difference! The total width is 960px.
However, when:

The code is as follows:

Div1
{
width:960px;
margin:0px;
padding:0px 10px 0px 10px;
}


At this point, Chrome will quit. She actually put the padding 20px on the outside, so that the total width of div1 is 960px+10px+10px=980px, and in IE, div1 width is still 960px;
According to my thinking, I feel padding should be counted in the width of the drop, did not expect chrome so stubborn.
After testing, border and padding, margin values are counted in the "width" of the outside.
Also, in the absence of a float, chrome will take div1 as a position:absolute, and IE will treat it as poisttion:relative; So, as far as possible, this is a block-level element of float left!
Really sad urges, the browser is not compatible let me this layman very painful!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.