CSS tutorial-element locating

Source: Internet
Author: User

1. position: static | no location
Position: static is the default value for positioning all elements. It is generally not required unless there is a need to cancel the inheritance of other positioning
Example:
The following is a reference clip:>
# Div-1 {
Position: static;
}
2. position: relative | relative positioning
When position: relative is used, top, bottom, left, and rightattributes are required to determine the position of the element.
If you want the div-1 layer to move 20 px down, move 40px left:
Example:
The following is a reference clip:
# Div-1 {
Position: relative;
Top: 20px;
Left: 40px;
} If relative positioning is used, the layer divafter that follows will not appear below the div-1, but will appear at the same height as the div-1.
It can be seen that position: relative; is not very useful.
3. position: absolute | absolute positioning
You can use position: absolute; to accurately move elements to the desired position,
Let me move the div-1a to the upper right corner of the page:
Example:
The following is a reference clip:
# Div-1a {
Position: absolute;
Top: 0;
Right: 0;
Width: 200px;
} Using the absolute positioning of the div-1a layer before or after the layer will think that this layer does not exist, does not affect them. So position: absolute; it is useful to place an element in a fixed position, but if you need to determine the position of the div-1a layer relative to the nearby layer, don't implement it.
* Here is a bug in Win IE. If you define a relative width for an absolutely positioned element, the width of IE depends on the width of the parent element rather than the width of the entire page.
4. position: relative + position: absolute | absolute position + relative position
If the parent element (div-1) is defined as position: relative; the child element (div-1a) is defined as position: absolute, then the position of the child element (div-1a) is relative to the parent element (div-1 ), instead of the entire page.
Place the div-1a in the upper right corner of the div-1:

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.