To fix the position of a layer by setting the Position property in the CSS _javascript tips

Source: Internet
Author: User

Definitions and usage

The Position property sets the positioning type of the element.

Description

This property defines the positioning mechanism used to establish the element layout. Any element can be positioned, but an absolute or fixed element generates a block-level box regardless of the type of element itself. The relative positioning element is offset from its default position in the normal stream.

Default value: Static
Inheritance: No
Version: CSS2
JavaScript Syntax: object. style.position= "Absolute"

Instance

To locate the H2 element:

H2
 {
 position:absolute;
 left:100px;
 top:150px;
 }
Tiy

Browser support

All major browsers support the Position property.

Note: The property value "Inherit" is not supported for any version of Internet Explorer (including IE8).

Possible values

Tiy instance

value Description
Absolute

Generates an absolutely positioned element that is positioned relative to the first parent element other than static positioning.

The position of the element is defined by the "left", "Top", "right" and "bottom" properties.

Fixed

Generates an absolutely positioned element that is positioned relative to the browser window.

The position of the element is defined by the "left", "Top", "right" and "bottom" properties.

Relative

Generates a relatively positioned element that is positioned relative to its normal position.

Therefore, "left:20" adds 20 pixels to the left position of the element.

Static The default value. There is no positioning, and the elements appear in the normal stream (ignoring top, bottom, leave, right, or z-index declarations).
Inherit Specify that the value of the position attribute should be inherited from the parent element.

Positioning: Relative Positioning This example demonstrates how to position an element in relation to its normal position. Positioning: Absolute Positioning This example demonstrates how to use absolute values to position an element. Positioning: Fixed Positioning This example demonstrates how to position an element relative to the browser window. Set the shape of an element This example shows how to set the shape of an element. This element is clipped to the shape and displayed. Z-indexz-index can be used to place an element after another element. Z-index the elements in the above example have changed Z-index.

Here's a description of the position attribute in CSS

CSS position is very important, has the following values: Static,relative,absolute,fixed.

Static: Statically positioned. If you do not set the position attribute, the default is static. Top,left,bottom,right properties, which are not valid in static situations, to use these properties, you must set the position to one of the other three values.

Relative: relative positioning. The element will be adjusted as it is positioned statically, and the space allocated to the element in static positioning will still be assigned to it, and the elements on either side will not be near it to fill that space, but they will not be squeezed out of the new position of the element.

Absolute: absolute positioning. The element is adjusted according to the position of the element that contains it, for example, it is nested within another absolutely positioned element, and is positioned relative to that element.

Fixed: stationary positioning. The element will be set to the last fixed position in the browser and will not scroll with other elements. Image Point said, pull up and down the scroll bar, fixed elements on the screen position unchanged. It is to be noted that IE6 does not support this attribute.

Note: Many pages are centered so that when the element is absolutely positioned, there will be deviations at different resolutions, at which point we can deal with a method like the following:

<div style= "position:relative;" >
<div style= "Position:absolute; top:10px; left:10px;" ></div>
</div>
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.