2015-02-11 76 views
0

在网站上,我想仅在用户在笔记本电脑或台式机上查看页面时加载背景图片。在移动版本中,我不希望图像显示,另外(!)我不希望它加载。仅在桌面版加载图像

什么是最好的方法来实现这一目标?

回答

1

请尝试下面的内容来获取bg图片的使用情况,具体取决于屏幕大小。您可以设置下面的示例中的另一块为另一个屏幕尺寸

@media screen and (max-width: 768px) { /* Adjust as needed */ 
    body { /* The element or whatever */ 
     background-image: none; 
    } 
    } 
+2

无需'important' ..只是就更难了OP以覆盖此!稍后点如果他们需要 – 2015-02-11 15:43:31

+1

注明并更改。 – 2015-02-11 16:02:05

1

使用的CSS:

//default css 
    body{ 
     background-image:url(images/image_de_fond.png); 
    } 

    @media screen and (max-width: 640px) { 
    // for screen under 640px width the following css will be applied 
     body{ 
      background-image:none; 
     } 
    }