"CSS" About position:absolute layouts

Source: Internet
Author: User

In a Web page, if you need the left and top properties to take effect, you must add Position:absolute to the style attribute of the Div, so that the div can be detached from the overall div layout, that is, before you add Position:absolute , all the div follows the various layouts I mentioned in the "CSS" about div alignment and page layout (click to open link).

For example, the following code:

<div style= "Position:absolute; left:100px; top:100px; width:20px; height:20px; border:1px solid #000000; " ></div>

You get the following effect:


If you remove the Position:absolute, then the left and top properties are not working, which is the following code:

<div style= "left:100px; top:100px; width:20px; height:20px; border:1px solid #000000; " ></div>
The resulting effect is this:

The layer with the black box is not moving at all as expected.

But it doesn't mean that this left and top is the distance from the top right corner of the browser. It is the distance from the superior div, if there is no superior div, then is the distance from the upper left corner of the browser, that is, relative to the body, the maximum layer of the page distance.

For example, the following code:

<div style= "Position:absolute; left:100px; top:100px; width:20px; height:20px; border:1px solid #000000; " ></div><div style= "Position:absolute; left:100px; top:100px; width:400px; height:400px; border:1px solid #000000; "><div style=" Position:absolute; left:100px; top:100px; width:20px; height:20px; border:1px solid #000000; " ></div></div>
The following effects are obtained:

First, the first layer is used to illustrate the layer, Position:absolute is not affected by the layout of any div, oneself free from the system,

Then, the second layer, no upper Div, so left and top after Position:absolute is the distance from the top left corner of the browser

Finally, the third layer, in the second layer, the upper div is the second layer, there is a superior div, so the left and top of the Position:absolute is its own top corner relative to the second layer of the upper left corner of the distance.

In addition, IE6 does not support position:fixed, so to achieve that hover effect, you might consider using Position:absolute and JavaScript reality.

"CSS" About position:absolute layouts

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.