Some details about the margin,padding used in the entire layout of the CSS layout

Source: Internet
Author: User

Recently in learning to write Web pages, when using HTML markup language and CSS layout, it is found that the margin,padding in CSS layout will make the whole layout bigger, and finally found the answer when studying CSS box model.

The main reason is that margin defines the outer margin of the module, and padding defines the inner margin of the module, if the two margins are not taken into account in the layout, and the width height in the parent layout is set to fixed, what happens is that if the width of the entire parent layout does not fit the child layout, Then the child layout will support the entire parent layout, for example:

<div id= "container" ><div id= "header" ></div><div id= "main" ><div id= "left" ></div ><div id= "rigt" ></div></div><div id= "Footer" ></div></div>

Layout as above, container is the parent layout, all the rest is child layout, when my sub-layout header is set to the width of the container setting, the code is as follows:

#container {width:820px;height:auto;background:white;margin:0 auto;background:yellow;} #header {width:840px;height:50px;background:green;margin:10px 0px 0px 10px;}

The following situation occurs:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7D/2A/wKioL1bhMG3hFzvTAAAO4Sl-_ps863.png "title=" 00001. PNG "style=" FLOAT:LEFT;WIDTH:500PX;HEIGHT:36PX; "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiol1bhmg3hfzvtaaao4sl-_ps863.png "/>



You can see that the green part has gone beyond the section, if the total width of the two sub-layouts side by sides exceeds the width of the parent layout, the layout on the right side will automatically appear below the left layout, with the following code:

#left {width:200px;height:200px;background:red;float:left;margin:10px 10px;} #rigt {width:600px;height:200px;background:blue;float:left;margin:10px 10px;}

Here the left layout width 200px, right layout width 600px, plus margin margin is 830px, more than the parent layout of 820px, so the situation is as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7D/2C/wKiom1bhMmribZSJAAAZRxmqSH4457.png "title=" 00002. PNG "alt=" Wkiom1bhmmribzsjaaazrxmqsh4457.png "/>

You can see that the right layout is lined up below the left layout. This blog is written here, I hope you can support.

Some details about the margin,padding used in the entire layout of the CSS layout

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.