群里有人发问求助,外层DIV的width和height改变,里面的DIV的大小也改变,相对位置又不变?
这里可以在内层使用百分比。不用多说,上代码:
<!DOCTYPE html>
<head>
<head>
<title></title>
<style type="text/css">
#siye
{
border: 2px solid blue;
width: 400px;
height: 500px;
}
#siye div
{
margin-top: 20px;
margin-left: 12px;
width: 80%;
height: 80%;
border: 1px solid blue;
}
</style>
</head>
<body>
<div id='siye' ><div ></div></div>
<button id="btn">dianwo
</button>
</body>
</html>
<script language="javascript" type="text/javascript">
document.getElementById("btn").onclick = function () {
document.getElementById("siye").style.width = "800px";
};
</script>