移动端基础-vw适配

什么是vw

相对单位

相对视口的尺寸

vw:viewport width

换算 1vw=1/100视口宽度

vw不需要向rem一样检查视口宽度

若视口宽为375px

1vw=3.75px

vw与vmin的区别

vmin更照顾横竖屏问题

1vw是视口宽度的100%,而vmin是找宽度和高度中最小的那个,这样横屏看着更舒服

移动端基础-vw适配_第1张图片移动端基础-vw适配_第2张图片

左图单位为vmin,右图用vw

案例





   
   
   


   bilibili-干杯~~~

   
   
   
   
   




   
@baseSize: 3.75vw;

.suspension {
    z-index: 1;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #fff;

    .m-navbar {
        padding: 0 (12 / @baseSize) 0 (18 / @baseSize);
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: (44 / @baseSize);

        .logo {
            img {
                width: (66 / @baseSize);
            }
        }

        .right {
            display: flex;

            .search {
                i {
                    color: #ccc;
                    font-family: 'icomoon';
                    font-size: (19 / @baseSize);
                }
            }

            .face {
                width: (24 / @baseSize);
                height: (24 / @baseSize);
                margin: 0 (20 / @baseSize);

                img {
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                }
            }

            .app-btn {
                border-radius: 4px;
                width: (72 / @baseSize);
                height: (24 / @baseSize);
                background-color: rgb(246, 14, 172);

                span {

                    display: flex;
                    justify-content: center;
                    color: #fff;
                    font-size: (14 / @baseSize);
                }
            }
        }
    }
}

.channel-menu {
    display: flex;
    justify-content: space-between;
    height: (40 / @baseSize);
    background-color: #fff;
    border-bottom: 1px solid #e8e5e5;

    .tabs {
        overflow: hidden;
        flex: 1;
        position: relative;

        .tabs-list {
            display: flex;

            a {
                padding: 0 (16 / @baseSize);
                white-space: nowrap;
                font-size: (14 / @baseSize);
                line-height: (40 / @baseSize);
            }

            .line-red {
                width: (28 / @baseSize);
                height: (2 / @baseSize);
                background-color: #fb7299;
                position: absolute;
                left: (16 / @baseSize);
                bottom: 0;
            }
        }
    }

    .after {
        width: (40 / @baseSize);
        height: (39 / @baseSize);
        text-align: center;
        line-height: (40 / @baseSize);
        background-color: #fff;

        i {
            color: #ccc;
            font-family: 'icomoon';
            font-size: (19 / @baseSize);

        }
    }
}

.m-home {
    padding: (85 / @baseSize) (5 / @baseSize) 0;

    .bottom {
        height: (38 / @baseSize);
        width: (351 / @baseSize);
        position: fixed;
        background-color: #fb7299;
        bottom: (20 / @baseSize);
        left: auto;
        border-radius: ((37 / 2) / @baseSize);
        text-align: center;
        line-height: (38 / @baseSize);

        span {
            color: #fff;
            font-size: (12 / @baseSize);
        }
    }

    .video-list {
        display: flex;
        flex-wrap: wrap;

        .video-item {
            width: 50%;
            padding: (8 / @baseSize) (5 / @baseSize);


            .title {
                width: 100%;
                height: (42 / @baseSize);
                margin-top: (5 / @baseSize);

                .ellipsis-2 {

                    font-size: (12 / @baseSize);
                }

            }

            .card {
                position: relative;
                height: (97 / @baseSize);
                width: 100%;

                img {
                    height: 100%;
                    width: 100%;
                }

                .count {
                    position: absolute;
                    height: (27 / @baseSize);
                    left: 0;
                    bottom: 0;
                    width: 100%;
                    padding: (5 / @baseSize);
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    background-image: linear-gradient(transparent, rgb(55, 54, 54));

                    span {
                        font-size: (12 / @baseSize);
                        font-family: 'icomoon';
                        color: #fff;
                    }
                }
            }
        }
    }
}

效果: 

                                移动端基础-vw适配_第3张图片

你可能感兴趣的:(前端,css,javascript)