CSS Position Properties

Source: Internet
Author: User

Instance

To locate the H2 element:

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

Try it yourself.

Browser support
IE Firefox Chrome Safari Opera

All major browsers support the Position property.

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

Definition and usage

The Position property specifies the positioning type of the element.

Description

This property defines the positioning mechanism used to create the element layout. Any element can be positioned, but an absolute or fixed element generates a block-level box, regardless of the type of the element itself. Relative positioning elements are offset relative to their default position in the normal flow.

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

Creates an absolutely positioned element that is positioned relative to the first parent element other than the static anchor.

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

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" attributes.

Relative

Creates a relative positioned element, positioned relative to its normal position.

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

Static The default value. No positioning, elements appear in the normal stream (ignoring top, bottom, left, right, or z-index declarations).
Inherit Specifies that the value of the position property should be inherited from the parent element.
Tiy instances
Positioning: Relative positioning
This example shows how to position a element relative to its normal position.
Positioning: Absolute Positioning
This example demonstrates how to use an absolute value to position an element.
Positioning: Fixed positioning
This example demonstrates how to position an element relative to a browser window.
Set the shape of an element
This example shows how to set the shape of an element. This element is clipped into this shape and is displayed.
Z-index
Z-index can be used after one element is placed on another element.
Z-index
The
elements in the above example have changed the Z-index.
Related pages

CSS Tutorial: CSS Positioning

HTML DOM Reference manual: Position properties

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.