【问题标题】:Changing background picture via @Media screen通过@Media 屏幕更改背景图片
【发布时间】:2020-08-16 22:21:24
【问题描述】:

所以我尝试在使用手机而不是浏览器时更改背景图像。背景是写在 style.CSS 文件中的,但显然我做错了什么,因为无论如何它都不会改变图片。

这是我的 CSS 代码。

body {
  font-family: "Open Sans", sans-serif;
  background-color: #040404;
  color: #fff;
  position: relative;
  background: transparent;
}

body::before {
  content: "";
  position: fixed;
  background:#040404 url("../img/Backgroundv.1.png") top right no-repeat;
  background-size: cover;
  left: 0;
  right: 0;
  top: 0;
  height: 100vh;
  z-index: -1;
}
@media screen and (max-width: 480px)
{
  body {
    content: "";
    position: fixed;
    background:#040404 url("../img/NormBackgroundMobile.png") top right no-repeat;
    background-size: cover;
    left: 0;
    right: 0;
    top: 0;
    height: 100vh;
    z-index: -1;
  }
}

非常感谢任何提示或回复。

【问题讨论】:

    标签: html css responsive-design media-queries


    【解决方案1】:

    一个小错误。改变

        body {
                content: "";
                position: fixed;
                background: #040404 url("../img/NormBackgroundMobile.png") top right no-repeat;
                background-size: cover;
                left: 0;
                right: 0;
                top: 0;
                height: 100vh;
                z-index: -1;
            }
    

    收件人:

        body::before {
                content: "";
                position: fixed;
                background: #040404 url("../img/NormBackgroundMobile.png") top right no-repeat;
                background-size: cover;
                left: 0;
                right: 0;
                top: 0;
                height: 100vh;
                z-index: -1;
            }
    

    您将 CSS 应用到 body 标签而不是伪元素

    【讨论】:

    • 我讨厌编程。解决了我的问题!非常感谢!
    【解决方案2】:

    你在选择器中使用图片body::before
    将媒体查询中的 body 更改为 body::before

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 2015-05-17
      • 1970-01-01
      相关资源
      最近更新 更多