背景大图平铺整个页面

方式一

<div class="content">
    <div class="bg_img">
        <img src="../../img/bg.png" />
    </div>
</div>

.content {
    position: fixed;  //关键是设置fixed定位,设置后即可通过height:100%设置标签高度为页面高度,无需js,神奇吧
    width: 100%;
    height: 100%;
    .bg_img {
        width: 100%;
        height: 100%;
        img{
            width: 100%;
            height:100%;
            background: url("../../assets/img/loginbg.jpg") no-repeat center;
            background-size: 100% 100%;  
            overflow: hidden;  //所需要设置内容区域滚动,则设置overflow:auto
        }
    }
}

方式二

<div class="content">
        <img class="bg_img" src="../../img/bg.png" />
</div>

.content {
    .bg_img{
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        z-index: -1;
    }
}
posted @ 2020-03-31 10:24  huihuihero  阅读(187)  评论(0编辑  收藏  举报