【问题标题】:CSS background image is not responsive in a browser on a real smartphoneCSS 背景图像在真实智能手机的浏览器中没有响应
【发布时间】:2020-05-18 11:25:18
【问题描述】:

我有下面这样的 CSS,在 PC 浏览器中测试时它是响应式的,我已经在响应式设计模式下测试过它是正常的,但是当我在手机上测试时,背景没有响应:

.imgBG {
  background: url(../../../assets/img/bg-img/bg-login-blur.jpg) no-repeat center center fixed;
  font-family: Open Sans;
  padding-top: 40px;
  padding-bottom: 40px;
  position: fixed;
  width:100%;
  height:100%;
  background-size:cover;
  background-position:center;
  background-repeat:no-repeat;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  padding:20px;
 }

我错过了什么,你能告诉我吗?

【问题讨论】:

  • 没有响应是什么意思?
  • 是的。当我在智能手机中测试时,我的背景图片没有响应

标签: html css image background responsive


【解决方案1】:

在您的 HTML 标头中添加:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

【讨论】:

    【解决方案2】:

    将此行添加到代码中background-attachment: fixed;

    【讨论】:

      【解决方案3】:

      使用此代码。

       .imgBG { 
          background-image: url(../../../assets/img/bg-img/bg-login-blur.jpg);
          background-repeat: no-repeat;
          background-position: center;
          background-size: cover;
          width: 100%;
          height: 100%;
      }
      

      【讨论】:

      • 已经尝试过这个.. 在智能手机中没有固定,但我在 PC 中测试最大化/最小化它的工作
      猜你喜欢
      • 2017-03-23
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多