Relative positioning and absolute positioning in CSS Web pages

Source: Internet
Author: User
Tags relative
css| Web page

In CSS there is an instruction like this: (position)

Translated as "positioning" in the DW Chinese version, the commonly used attributes are relative (relative) and absolute (absolute).

A lot of friends are still not clear about the use of this instruction, here do some meticulous explanation:

position:relative; Indicates relative positioning, where the label of the attribute can be moved up or down in the range of the property in which the movement is not the same as the position change produced by the padding or margin. Padding and margin are the elements themselves a kind of margin and padding distance is not really moving, and the element defined as relative is real movement, which produces a moving distance from the periphery of margin to the inside of the parent label.

Position:absolute; Represents absolute positioning, and if the element of this property is defined, its position is calculated based on the 0 points in the upper-left corner of the browser and is above the floating normal element. Then you can use this property when you need an element positioned somewhere in the browser's content area.

Then there is a problem, and now we do most of the Web page is centered, then I need this element to follow a page in the location of a certain element regardless of the resolution of his position is always on the page of an element, so simple absolute is not.

The correct solution is to define the element's parent element as position:relative; (correction: This can be a grandparent, or it can be a position:absolute; thank old9 for the proposal) the element that requires absolute positioning is set to position: absolute;

This then set the value of the top,right,bottom,left can be, so that its positioning of the reference standard is the upper left corner of the parent padding the upper left side!



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.