
div嵌套另一个 ,如何让内层DIV靠左下
1个回答
展开全部
如果知道两个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: 300px;
width: 300px;
background-color: #CC9900;
position: absolute;
bottom: 0px;
}
-->
</style>
</head>
<body>
<div id="out">
<div id="in"></div>
</div>
</body>
</html>
这样不知道你满意吗?
<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: 300px;
width: 300px;
background-color: #CC9900;
position: absolute;
bottom: 0px;
}
-->
</style>
</head>
<body>
<div id="out">
<div id="in"></div>
</div>
</body>
</html>
这样不知道你满意吗?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询