A detailed description of the use of auto properties in CSS

Source: Internet
Author: User
-What is auto?

+auto is self-adapting, auto is the default value for many dimension values, which is calculated automatically by the browser.

+ The sum of the margin, border, padding, and content widths of the block-level elements form the parent element width.

When the Auto property is used, the width of the parent element changes, and the width of the element changes.

The values in auto are the sum of the margin, border, padding, and content widths.

+ But when the element is set to float , the width of the element becomes the contents of the content , the content is open, that is, the so-called parcel .

Overflow | position:absolute | Float:left/right All can produce the package sex, The replacement element is also wrapped.

*|position:relavtive| relative positioning occupies the original position, can not achieve the transformation of the mode, that is, does not have a package.

Therefore, it is not possible to use Width:auto on a package element, so that the width of the element is adaptive to the browser width. As shown

-sometimes set margin:0 auto; not working?

+maigin:0 Auto; The upper and lower margins of the element are 0, and the left and right margins are adaptive to the parent element (body) width, which is centered horizontally around the left and right. If the setting does not work for roughly the following two reasons.

+ (1) No width is set for P, and if p is width, it is not possible to refer to the width of the parent element for auto.

+ (2) p has a wrapper, that is, out of the standard flow, just like the parent object in the standard flow analogy to the surface, the parcel of the element is already heaven. Auto is not available as a reference to the width of the parent element.

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.