Javascript examples for CSS Style Property:top
The top property sets or gets the top position of a positioned element.
Value | Description |
---|---|
auto | Lets the browser calculate the top position. Default |
length | Sets the top position in length units. Negative values are allowed |
% | Sets the top position in percentage?of the height of the parent element |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
Item | Value |
---|---|
Default Value: | auto |
Return Value: | A String, representing the top position of a positioned element |
CSS Version | CSS2 |
Set the top position of a <button> element:
<!DOCTYPE html> <html> <body> <div id="myDiv" style="position:absolute;top:75px;">This is a div.</div> <button type="button" onclick="myFunction()">Return top position of div</button> <script> function myFunction() {//from w w w . ja va 2 s . c om document.getElementById("myDiv").style.top = '20px'; } </script> </body> </html>