vue背景图片铺满整个屏幕
背景全屏,不用定位内容完全显示且可滚动查看
html:
<div id="home"></div>
css:
<style>
#home {
  width: 100%;
  min-height: 100vh;
  background: url("~@/images/home/h_bg.png") center center no-repeat;
  background-size: 100% 100%;
  
}
</style>固定一屏大小,内容超出一屏会显示不全,不可滚动查看内容
html:
<div id="home"></div>
css:
<style>
#home {
  width: 100%;
  height: 100vh;
  background: url("~@/images/home/h_bg.png") center center no-repeat;
  background-size: 100% 100%;
  position: fixed;//固定定位
}
</style>背景全屏,内容完全显示且可滚动查看
html:
<div id="home"></div>
css:
<style>
#home {
  width: 100%;
  height: 100vh;
  background: url("~@/images/home/h_bg.png") center center no-repeat;
  background-size: 100% 100%;
  position:absolute;//绝对定位
}
</style>vue创建铺满整个页面的背景图
最近在做登陆页面时,遇到背景图不能完全展示,图片会自动切割重复显示等情况。经过一番搜索大佬的方法后终于发现解决方法。
网上一搜都是一堆的复杂方法,经过精简之后 代码如下。
<!-- 布局容器 --> <div id="all"></div>
使用top和left去除默认和浏览器的边距,设置背景图重复方式为no-repeat不重复
设置宽度高度为100%盛满全屏 设置固定位置 不跟随浏览器比例变化而变化
    <style>
        #all {
          top: 0;
          left: 0;
          background: url("@/assets/login/login_bg.jpg") no-repeat;
          background-size: 100% 100%;
          width: 100%;
          height: 100%;
          position: fixed;
        }
    </style>总结
总结以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
            
                                            
                                            
                                            
                                            
                                            
发表评论