Using negative values to Set the top position of a <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:top

Description

Using negative values to Set the top position of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*from   w  w  w .  j  ava2 s.c o  m*/
    border: 1px solid #FF0000;
    position: relative;
}
</style>
</head>
<body>

<div id="myDiv">This is a div.</div>
<br>

<button type="button" onclick="myFunction()">Set top position of div to -10 px</button>

<script>
function myFunction() {
    document.getElementById("myDiv").style.top = "-10px";
}
</script>

</body>
</html>

Related Tutorials