【问题标题】:How to incorporate responsive background images that exceed browser height?如何合并超过浏览器高度的响应式背景图像?
【发布时间】:2021-10-06 17:55:26
【问题描述】:

我的背景图片超出了浏览器的高度。我如何合并图像以便向下滚动以查看剩余部分,同时保持不同浏览器大小的比例?我编写或使用的代码仅剪切图像以适合浏览器的大小。溢出似乎没有影响。

【问题讨论】:

    标签: html css image responsive-design responsive


    【解决方案1】:

    根据您正在寻找的最终结果,您可以考虑以下一些方法和工具。

    @media(max-width:480px){ 
        body{
           background-image:URL(mobile-background.jpg);
        }
     }
    
    @media(min-width:481px){ 
        body{
           background-image:URL(desktop-background.jpg);
        }
    }
    • 封面或包含的背景图像大小也非常有用。指定 contain 意味着背景图像将被缩放以适应它所应用的元素的大小。

    并且指定 cover 意味着它将填充它应用到的元素的背景,并且您应该期望对背景图像进行一些裁剪。您还可以定位图像。
    更多信息:https://developer.mozilla.org/en-US/docs/Web/CSS/background-position

    div{  
       background-size: contain;  
       /* or */
       background-size: cover;
       background-position: center;
    }

    div{
       background-attachment: fixed;
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2019-11-02
      • 2015-09-28
      • 2013-12-12
      • 1970-01-01
      相关资源
      最近更新 更多