DIV + CSS two box models (W3C box and IE box), cssw3c

Source: Internet
Author: User

DIV + CSS two box models (W3C box and IE box), cssw3c

Before analyzing the two box models, let's briefly describe what the box model is.

Principle:

First, let's talk about the attribute names that we often hear in web design: content, padding, border, and margin all have these attributes. These attributes can be transferred to the boxes in our daily life for understanding. The boxes we see in our daily life are a kind of boxes that can hold things. They also have these attributes, so it is called the box mode. Features: each box has four attributes: border, border, fill, and content. Each attribute includes four attributes: Top, right, bottom, and left. These attributes can be set at the same time, you can also set the thickness of the anti-seismic auxiliary materials, and the border is divided into large and small colors. We can also understand the thickness of the box seen in life and what color material the box is made, the boundary is the distance between the box and other things. ( The above principles and features are summarized in Baidu)

The following figure shows the W3C and IE boxes:

We can certainly find that these two models are very similar in general. Content, padding, border, and margin are used from the inside to the outside. However, the height and width of the Extended parts of the dotted line are marked respectively. However, in W3C, only content is contained in the dotted line, while in IE, content + padding + border is surrounded by dotted lines. This is the most intuitive difference, and the biggest difference between the two models.
The W3C box model has the following scopes: margin, border, padding, and content, and the content Part does not contain other parts.
The range of the IE box model also includes margin, border, padding, and content. Unlike the standard W3C box model, the content part of the IE box model contains border and padding.

Use an example to implement the W3C box model:

<Html> 

Running result:

This figure only shows the content and border. If you do not see the specific demarcation line, you do not know the specific layout of the padding and content.
Here I will introduce the debugging tool No. 1, firebug in the firefox browser, which is of great help for debugging webpage layout.

The debugging interface is like this. When you select the <div> label, the image changes and the overall layout is clear. (For example)

This is clear. The W3C box contains three parts: content, padding, and border.
The IE box won't be written. If you need it, you can try it on your own. Currently, most web pages use W3C boxes, which have excellent compatibility, so they are the best choice.





CSS + DIV write box model Diagram

There are two web box models:
1: Standard W3C box model; 2: IE box model (default model of IE browser ).
In the two different model Web pages, the display effects of elements defining the same CSS attributes are different. The following uses a formula to distinguish the two different box models.
1: Standard W3C Box Model
Width = width + (padding-left) + (padding-right) + (margin-left) + (margin-right) + (border-left) + (border-right)

Height = height + (padding-top) + (padding-bottom) + (margin-top) + (margin-bottom) + (border-top) + (border-bottom)
2: IE Box Model
Width = width + (border-left) + (border-right)
Height = height + (border-top) + (border-bottom)
This model is the default box model of IE browser. You can also change it. Add the following code at the top of the page:

1 <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "www.w3.org/..al.dtd">

What is the difference between the IE box mode and the W3C box mode (HTML, css)

The standard W3C officially defined box model only contains the width and height of the content and border, and does not include the internal and external margins, while the IE box model calculates both the internal and external margins of the content border.
 

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.