DIV 始终位于文档底部

你说的曾经没有我的故事 提交于 2019-12-28 23:55:00

DIV 始终位于文档底部

  1. 设置body为绝对定位,最小显示高度为:100%,宽度为:100%
  2. 设置底部显示块为绝对定位,bottom: 0,是body元素的最后一个直接子元素;
  3. 设置底部块元素同级元素的上一个兄弟元素边距可以包含下底部元素即可;
<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        .slibing-div{
            border: 2px red solid; 
            height: 200px; 
        }
        .footer{
            border: 2px blue solid;
        }
    </style>
</head>
<body style="min-height: 100%; width: 100%; position: absolute;">
    <div style="margin-bottom: 100px;" class="slibing-div">
        <div style="text-align: center">测试用例</div>
    </div>

    <div style="position: absolute; bottom: 0; width: 100%; height: 100px;" class="footer">
        底部块
    </div>
</body>
</html>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!