CSS Position Properties Absolute relative five value interpretation

Source: Internet
Author: User
This article mainly introduces the CSS position properties absolute relative and other five values of interpretation, has a certain reference value, now share to everyone, have the need for friends can refer to

Currently almost all major browsers support the position attribute (except "Inherit", "Inherit" does not support all including IE8 and previous versions of IE, IE9, IE10 has not been tested), the following is w3school to position five value interpretation, A friend you need can refer to the following

Currently almost all major browsers support the position attribute (except "Inherit", "Inherit" does not support all including IE8 and previous versions of IE, IE9, IE10 has not been tested), the following is w3school to position five values interpretation:

Among them, absolute and relative are the most commonly used, fixed used more (where IE6 does not support fixed).

1, absolute (absolute positioning)

Absolute is an element that generates a sleep-to-position, out of the text stream (i.e. no longer occupies a position in the document), and is positioned by Top,right,bottom,left (TRBL), referring to the upper-left corner of the browser. You can select a parent object that has a location (which will refer to the combination of relative with absolute) or the body coordinate origin, or it can be hierarchically graded by Z-index. Absolute is based on the coordinates of the parent object as the starting point when the TRBL value is not set, and when the TRBL value is set, it is based on the top left corner of the browser as the original point. The specific cases are as follows:

Copy Code

The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


This code produces the following effects:

This is the effect after setting the TRBL (set TRBL to the top left corner of the browser), when the TRBL is not set (the TRBL is not set to the parent object's coordinates as the origin), will be P1 changed to the following code

Copy Code

The code is as follows:

. p1{            width:200px;            height:200px;            Background: #0099FF;            /* Not set trbl*/            position:absolute;    }

The effect is as follows:

2, relative (relative positioning)

Relative is a relative meaning, as the name implies is relative to the element itself in the document should appear in the position to move the element, you can move the position of the element through the TRBL, in fact, the element still occupies the original position of the document, but the position of the visual relative to the previous move. The specific cases are as follows:

Copy Code

The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

The code produces the following effects:

3. Combined use of relative and absolute

In the design of the Web page often use floating to the layout of the page, but the volatility caused by a lot of uncertainties (such as: IE browser compatibility problem). Relatively speaking, locating in some layouts is easier, faster, and more compatible (using relative with absolute), which is illustrated by an instance of the Web page (the Head section of the Web page), as follows:

Copy Code

The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Effects such as:

In the above code, the first is to set the head relative positioning, then you can see that all the child elements in the set absolute after the relative head positioning, rather than relative body positioning. This is relatively simple and convenient compared to floating, and there is no need to worry about compatibility issues.

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.