Positioning of CSS

Source: Internet
Author: User

Positioning direction: Left | Right | Top | Bottomposition:static

static positioning. The default value is the document flow

Position:absolute

Absolute positioning features

    • Element does not occupy the original position after using absolute positioning (off-label)
    • The element uses absolute positioning, the position is from the browser
    • Nested boxes, the parent box does not use positioning, the sub-box is absolutely positioned, the sub-box position is from the browser.
    • Nested box, parent box using positioning, sub-box absolute positioning, sub-box position is from the parent element position
    • After using absolute positioning for inline elements, convert to inline blocks. (not recommended, recommended for use with Display:inline-block;)
Position:relative

Relative positioning features

    • Using relative positioning, the position starts from itself
    • Still occupy the original position.
    • = = Child Absolute Parent (relative positioning of parent element, absolutely positioning of child elements) = =
    • Inline elements use relative positioning to not switch to inner block
Position:fixed

Fixed positioning features

    • Fixed positioning, does not occupy the original position (off the mark)
    • The position is set from the browser after using fixed positioning
    • Elements are converted into inline blocks after using fixed positioning (not recommended, Display:inline-block are recommended;)
The Positioned box centers the display
    • margin:0 Auto; You can only center the box of the standard flow.
    • Centered box: Half 50% of the parent's box is left, and half of the box (margin-left: Negative value). )
.nav{    width:500px;    height:60px;    left:50%;    margin-left:-480px}
Tags contain specifications
    • Div can contain all the tags
    • P tags cannot contain tags such as div h1
    • H1 can contain labels such as P,div
    • Inline elements contain inline elements as much as possible, and inline elements do not contain block elements
Bypass off-label flow
    • Use standard flow as much as possible
    • Standard flow can not solve the use of floating
    • Floating can not solve the use of positioning

Positioning of 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.