css实现占满屏幕高度

需求

实现div占满整个屏幕

结构

<body>
    <div class="cotent"></div>
</body>

1)通过css高度100%,但是要div的父级元素高度为100%

html,
body {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}
.cotent {
    width: 100%;
    height: 100%;
}

前提:以知父级元素并且父级元素高度可控

2)通过100vh

.cotent {
    height: 100vh;
}

前提:适合移动端或者不用兼容IE的项目

3)使用定位拉伸

.cotent {
    position: absolute;
    bottom: 0px;
    top: 0px;
 }

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容