Javascript examples for CSS Style Property:position
The position property sets or gets the type of positioning method as:
Value | Description |
---|---|
static | Elements renders in order, as they appear in the document flow. This is default. |
absolute | positioned relative to its first positioned not static ancestor element |
fixed | positioned relative to the browser window |
relative | positioned relative to its normal position |
sticky | positioned based on the user's scroll position. |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
Item | Value |
---|---|
Default Value: | static |
Return Value: | A String, representing the position type of an element |
CSS Version | CSS2 |
Change the position of a <div> element from absolute to relative
<!DOCTYPE html> <html> <body> <h2 id="myH2" style="position:absolute;left:100px;top:150px;">This is a heading</h2> <button type="button" onclick="myFunction()">test</button> <script> function myFunction() {//w w w. j av a 2 s.c o m document.getElementById("myH2").style.position = 'relative'; } </script> </body> </html>