css怎么控制div位于容器最下方

如题所述

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>底部对齐</title>
    <style>
    #a{
        margin: 0 auto;
        width: 500px;
        height: 500px;
        background: #CCCCE7;
        position: relative;            /* 父级容器相对定位 */
    }
    #b{
        width: 200px;
        height: 200px;
        background: green;
        position: absolute;        /* 相对于容器绝对定位 */
        bottom: 0px;            /* 距离容器底部0px,无论容器高度多少,
                                      都距离底部0px */
    }
    </style>
</head>
<body>

<div id="a">
    <div id="b"></div>
</div>

</body>
</html>

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答