div嵌套另一个 ,如何让内层DIV靠左下

来源:百度知道 编辑:UC知道 时间:2024/09/21 10:45:11

如果知道两个div的高度的话,直接设置内层div的上边界或者外层div的上填充就行。比如:
<html>
<head>
<title>无标题文档</title>
<style type="text/css">
<!--
#out {
height: 400px;
width: 400px;
background-color: #CCCCCC;
}
#in {
height: 300px;
width: 300px;
background-color: #CC9900;
margin-top: 100px;
}
-->
</style>
</head>

<body>
<div id="out">
<div id="in"></div>
</div>
</body>
</html>

如果不知道外层div的高度的话,则可以先设置外层div为相对定位,然后设置内层div为绝对定位(因为绝对定位会脱离标准流,以他的包含块为基准进行偏移),让内层div的下边界与外层div偏移0像素即可。代码如下:
<html>
<head>
<title>无标题文档</title>
<style type="text/css">
<!--
#out {
height: 400px;
width: 400px;
background-color: #CCCCCC;
position: relative;
}
#in {
height