CSS Box model

Source: Internet
Author: User

The box model in CSS is commonly used in page layout positioning, and the box model consists of three parts: 1 content Area 2 border Border 3 padding padding 4 margin margin each element has a box model,

In the Web world, box models are ubiquitous. The padding and margins and borders can be applied to all edges of an element, or to individual edges, and margins can be negative, and in many cases negative margins are now used

In CSS, width and height are the widths and heights of the content area (element). Increasing the padding, borders, and margins does not affect the size of the content area, but increases the total size of the element box. Assume that each side of the box has

10-pixel margins and 5-pixel padding. If you want this element box to reach 100 pixels, you need to set the width of the content to 70 pixels,padding(padding):padding-top,padding-bottom

, padding-left,padding-right margin(margin):Margin-top,margin-bottom, Margin-left,margin-right When margin is set to a negative number, the block that is set to a negative number is in the opposite direction

Moving, even covering the other blocks. When there is a parent-child relationship between blocks, by setting the margin parameter of the child block to a negative number, you can "detach" the child block from the parent block, and the elements in the box model are divided into block-level elements and inline elements

Two block-level elements have overlapping effects in the box model, causing them to collapse to produce a BFC, and you can set the element to hide overflow from overflow:hidden so that it does not overlap. The inline element cannot be set to its width, height, and margin in the box model.

And the inner margin is set vertically, the margin does not change and the horizontal setting changes.

CSS Box model

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.