相对定位.布局


<html>
<head>
<style type="text/css">
*{
margin:0;
padding:0;
}
#id1{
position:relative;
border:1px solid;
}
#id2{
position:relative;
boreder:1px solid;
width:100px;
height:100px;
}
#id3{
position:retive;
border:1px solid;
width:100px;
height:100px;
}
</style>
<script type="text/javascript">
function createDialog(){
var dialogs=document.getElementById("dialogs");//获取id
var noSizeDiv=document.createElement("div");//插入一个div
noSizeDiv.style.width=0;//设置该div的宽度和高
noSizeDiv.style.height=0;

var div=document.createElement("div");
var index=dialogs.children.length;//编号
div.style.position="relative";
div.style.height="100px";
div.style.width="100px";
div.style.border="1px solid";
div.style.left=(100+20*index)+"px";
div.style.top=(100+20*index)+"px";

noSizeDiv.appendChild(div);
dialogs.appendChild(noSizeDiv);
}

function increaseHeight(){
var div=document.getElementById("id1");
div.style.height=(20+parseInt(div.style.height))+"px";//增加20px
}
</head>
<body>
<button onclick="increaseHeight()">增高</button>
<button onclick="createDialog()">增高</button>
<div id="dialogs" style="height:2000px;">
<div style="width:0;height:0"> //套一个空的div
<div id="id1" style="left:100px;top:100px;width:100px;height:100px"></div>
</div>
<div style="width:0;height:0">
<div id="id2" style="left:120px;top:120px;"></div>
</div>
<div style="width:0;height:0">
<div id="id3" style="left:140px;top:140px;"></div>
</div>
</div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值