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

 我来答
yangwenguan
推荐于2016-03-23 · TA获得超过106个赞
知道答主
回答量:120
采纳率:0%
帮助的人:78.8万
展开全部
如果知道两个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>

这样不知道你满意吗?
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式