I have one parent div with style position relative and couple divs inside that div with style absolute like
<div id="container" style="position:relative;width=400px;height=400px;">
<div style="top:20px;left:20px;width:20px;height:20px;"></div>
<div style="top:40px;left:40px;width:20px;height:20px;"></div>
<div style="top:60px;left:60px;width:20px;height:20px;"></div>
</div>
How to add new div to div with id="container"
with top="0px" left="0px"
?
$('#container').append(
$('<div/>').css({top:'0px',left:'0px'})
);
Here's a live example: http://jsfiddle.net/AWYbD/
first, be careful to set "position: absolute" to your inner divs. This is not implicitely set when using the top, left, etc declarations.
To add a new div (I assume using jquery),
just do
$('#container').append('<div style="position:asbolute; top: 0px; left: 0px;"></div>');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.