A box with a wide height of auto in CSS

Source: Internet
Author: User

In the CSS box model, the Auto attribute only applies to external margin and width,border and padding are not applicable. Here's what it's about. All that is said here is the standard flow box.

1. Horizontally Speaking

(1) If you set a value in Width,magrin-left,margin-right to auto and the remaining two to the specified value, the property set to auto determines the desired length, so that the width of the element is equal to that of the parent element. For example, the box's transverse length must be equal to 400px, without setting padding and border,margin-right and width set to 100px, and the left margin set to auto, then the width of the left margin will be 200 pixels.

(2) if not set to auto, the above example, the left and right margin and width are set to a pixel (formatting attributes are too limited), at this time will always force margin-right to auto;

(3) When there is more than one auto. If these three attributes left and right margin and width, two are set to auto;

If Margin-right and Margin-left are set to auto, the two are set to equal lengths, so the element is centered in the parent element ( this is a method to center the element, and text-align applies only to inline content of the block-level element. Set it to center and cannot center this element )

If you set a margin and width to auto and the other margin is set to a specified pixel, the margin set to auto will be reduced to 0,width and set to the desired value;

If three are set to auto, this result is the same as the default result, that is, the margin is 0, the width defaults to auto;

2. Auto Height

If the block level normal flow element is set to Height:auto;

(1) for inline content (including text), the height of the display is exactly enough to contain the line height of the inline content. A border is set on the element paragraph, and it is thought that there is no padding, so that the bottom border is just below the last line of the text, and the top frame is above the first line of text;

(2) If there is only a block-level child element, its default height will be the distance from the bounding box boundary of the highest block-level child element to the outer border boundary of the lowest child element. Thus, the margin of the child element "exceeds" the element containing the child element, however, if the block level element (that is, the parent element) has an inner margin or a border, its auto height is the distance from the sisu boundary of the highest child element to the bottom margin boundary of the lowest child element;

A box with a wide height of auto in CSS

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.