css - 将div定位到包含div的底部 [英] css - position div to bottom of containing div

查看:361
本文介绍了css - 将div定位到包含div的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将div定位到包含div的底部?

How can i position a div to the bottom of the containing div?

<style>
.outside {
    width: 200px;
    height: 200px;
    background-color: #EEE; /*to make it visible*/
}
.inside {
    position: absolute;
    bottom: 2px;
}
</style>
<div class="outside">
    <div class="inside">inside</div>
</div>

此代码将文本inside放在页面底部。

This code puts the text "inside" to the bottom of the page.

推荐答案

.outside {
    width: 200px;
    height: 200px;
    background-color: #EEE; /*to make it visible*/
}

需要

.outside {
    position: relative;
    width: 200px;
    height: 200px;
    background-color: #EEE; /*to make it visible*/
}

绝对定位寻找最近的相对定位父项,如果没有定义它将使用正文。

Absolute positioning looks for the nearest relatively positioned parent within the DOM, if one isn't defined it will use the body.

这篇关于css - 将div定位到包含div的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆