vw/vh的概念

vw是把设备视口宽度均分为100份,每一份就是1vw \
vh是把设备视口高度均分为100份,每一份就为1vh \
vmin/vmax 选取vw/vh中最小/最大的一个

兼容性

在移动端 ios 8 以上以及 Android 4.4 以上获得支持,并且在微信 x5 内核中也得到完美的全面支持

例子

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .header{
            position: fixed;
            left: 0;
            top: 0;
            width: 100vw;
            height: 50px;
            background-color: chartreuse;
        }

        .contents{
            position: fixed;
            left: 0;
            top: 50px;
            width: 100vw;
            height: calc(100vh - 50px - 40px);
            background-color: brown;
            overflow-y: scroll;
        }

        .footer{
            position: fixed;
            left: 0;
            bottom: 0;
            width: 100vw;
            height: 40px;
            background-color: darkgray;
        }
    </style>
</head>
<body>
    <header class="header">

    </header>
    <section class="contents">
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        1<br>
        2<br>
    </section>
    <footer class="footer">

    </footer>
</body>
</html>
Last modification:June 3rd, 2020 at 01:21 am
如果觉得我的文章对你有用,请随意赞赏