【问题标题】:How to remove background image for mobile site? [closed]如何删除移动网站的背景图片? [关闭]
【发布时间】:2013-12-24 03:23:33
【问题描述】:

我的桌面网站上有一张背景图片。然而,由于它的大小,它使移动网站变得缓慢且不成比例。是否可以删除移动网站的背景图片或至少使其具有响应性?

【问题讨论】:

  • 没有发布代码,您不太可能得到代码作为答案。您不想从移动设备中删除,而是要为平板电脑/台式机添加,以便从最小向上工作,因此在遇到适用于大于任何值的屏幕尺寸的媒体查询之前,不会设置您的背景。

标签: css twitter-bootstrap mobile background-image


【解决方案1】:

其实隐藏背景图片here就是简单的css:

background-image: none;

这是移动解决方案,我使用了媒体查询

HTML

<div class="bgimg" >

</div>

外部 CSS

/* Show in Large desktops and laptops */
@media (min-width: 1200px) {

.bgimg {
        background-image: url('../img/your-eternity.jpg');
        background-repeat: no-repeat;
        height: 800px;
        width: 1000px;
        background-size:100% auto;
    }

}

/*Hide in Other Small Devices */


/* Landscape tablets and medium desktops */
@media (min-width: 992px) and (max-width: 1199px) {

      .bgimg {
        background-image: none;
    }

}

/* Portrait tablets and small desktops */
@media (min-width: 768px) and (max-width: 991px) {

          .bgimg {
        background-image: none;
    }

}

/* Landscape phones and portrait tablets */
@media (max-width: 767px) {

          .bgimg {
        background-image: none;
    }

}

/* Portrait phones and smaller */
@media (max-width: 480px) {

          .bgimg {
        background-image: none;
    }

}

希望能帮助别人。

【讨论】:

    【解决方案2】:

    下面的代码改编自 Tim Kadlec 的精彩 blog post,其中介绍了有条件地显示背景图像的各种场景。

    对于您的方案,移动版本设置为与其父元素的宽度相匹配。根据您的布局,您可能需要设置/限制 #container 所在元素的大小。

    如果您选择在移动设备上隐藏背景图片,则第一个样式块将进入第一个媒体查询,而第二个可能会被消除。正如 popnoodles 提到的,发布一些代码可以更容易地提供更具体的解决方案。

    <div id="container"></div>
    
    #container {
      background-image: url('images/bg.png');
    }
    
    @media all and (min-width: 601px) {
        #container {
            width:200px;
            height:75px;
        }
    }
    @media all and (max-width: 600px) {
        #container {
            max-width: 100%;
            background-size: 100%;
        }
    }
    

    【讨论】:

      【解决方案3】:

      您可以使用媒体查询为桌面版网站和移动版网站指定不同的 css 规则。

      参考How to use CSS media query to scale background-image to viewing window

      使用媒体查询取决于屏幕的分辨率,我们可以设置样式。 有关媒体查询的更多信息,请参考https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

      您也可以参考
      http://mobile.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/ 来创建您的网站的移动版本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-29
        • 1970-01-01
        相关资源
        最近更新 更多