Css3 box model and css3 Model

Source: Internet
Author: User

Css3 box model and css3 Model

Css2.1 box model:

When you define the width and height of the box, if the padding and border values are added, the width and height of the box will be extended.

Height of the box = defined height + (padding-top + padding-bottom) + (border-top + border-bottom );

Box width = defined width + (padding-left + padding-right) + (border-left + border-right );

Css3.0 box model:

After you define the height of the box, if the size of the box does not change after adding the padding and border values, it will shrink to the content area.

The height of the box = the height you define; the width of the box = the width you define;

Usage:

Box-sizing: the box model resolution mode used to control elements

Box-sizing: content-box | border-box | inherit;

The default value is content-box: Maintain the W3C standard box model, that is, the layout of versions earlier than css3.0.

Border-box: redefine the mode composed of the box model.

Inherit: enables the element to inherit the box model of the parent element.

Writing Method (considering compatibility ):

-Moz-box-sizing: border-box;
-- Webkit-box-sizing: border-box;
-Moz-box-sizing: border-box;
-Ms-box-sizing: border-box;
Box-sizing: border-box;

Instance:

<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta charset = "UTF-8">
<Title> css3 layout </title>
</Head>
<Style>
* {Margin: 0; padding: 0 ;}
. Wrapper {
Width: 960px;
Margin: 0 auto;
Color: # fff;
Background: # cccccc;
Text-align: center;
-Moz-box-sizing: border-box;
-- Webkit-box-sizing: border-box;
-Moz-box-sizing: border-box;
-Ms-box-sizing: border-box;
Box-sizing: border-box;
}
. Header {
Background: # 38382e;
Margin-bottom: 10px;
Border: 10px solid red;
Padding: 10px;
Width: 100%; height: 100px;
Box-sizing: inherit;
}
. Sidebar {
Float: left;
Width: 220px;
Margin: 0px 20px 10px 0px;
Height: 300px;
Background: # 5d33cf;
Border: 10px solid red;
Padding: 10px;
Box-sizing: inherit;
}
. Content {
Float: left;
Width: 720px;
Margin-bottom: 10px;
Height: 300px;
Background: # c8ca30;
Border: 10px solid red;
Padding: 10px;
Box-sizing: inherit;
}
. Footer {
Clear: both;
Width: 100%;
Height: 100px;
Background: # cc4ad5;
Border: 10px solid red;
Padding: 10px;
Box-sizing: inherit;
}
</Style>
<Body>
<Div class = "wrapper">
<Div class = "header"> header </div>
<Div class = "sidebar"> left sidebar </div>
<Div class = "content"> main content </div>
<Div class = "footer"> footer </div>
</Div>
</Body>
</Html>

Effect:

Related Article

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.