0
   

help me out in positioning div.

 
 
Reply Sat 2 May, 2015 02:21 pm
I just learnt javascript and was playing with javascript and css.
In this code ,I wanted to know if there is a way to place the child div's side by side instead of overlapping.

<!doctype html>
<html>
<head>
<style type="text/css">

#parentdiv
{
margin-top: 10px;
height:800px;
width:800px;
position: relative;
border:1px solid black;
}
</style>
</head>

<body>

<script type="text/javascript">
var counter=1;
function create()
{
var newdiv = document.createElement("div");
newdiv.style.width = "100px";
newdiv.style.height = "100px";
newdiv.style.background = "red";
newdiv.style.border = "1px solid black";
newdiv.style.color ="white"
newdiv.innerHTML = counter++;
newdiv.style.position = "absolute";
newdiv.style.float="left";
newdiv.style.top = document.getElementById("textField").value + "px";

document.getElementById("parentdiv").appendChild(newdiv);
}
</script>

Enter position from top:
<input type="text" id="textField">
<input type="button" value="Create child Div " id="new button" onclick="create()"/>
<div id="parentdiv"></div>
</body>
</html>
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 554 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » help me out in positioning div.
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 04/19/2024 at 05:41:09