Css 检测到移动设备时隐藏身体背景

Css 检测到移动设备时隐藏身体背景,css,Css,我希望当我的网站是从智能手机或平板电脑的背景访问 不显示。使用媒体查询概念执行此操作 /*智能手机(纵向和横向)*/ body { background:url(../img/background_leftside.png), url(../img/background_rightside.png); background-position:left top, right top; background-repeat: repeat-y; background-attachment:fixed;

我希望当我的网站是从智能手机或平板电脑的背景访问
不显示。

使用
媒体查询
概念执行此操作

/*智能手机(纵向和横向)*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*智能手机(景观)----*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*智能手机(肖像)*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*iPad(纵向和横向)*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*iPad(景观)----*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*iPad(人像)----*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*台式机和笔记本电脑--------*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*大屏幕--------*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}
/*iPhone4------*/

body {
background:url(../img/background_leftside.png), url(../img/background_rightside.png);
background-position:left top, right top;
background-repeat: repeat-y;
background-attachment:fixed;
word-wrap: break-word;
}    
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}
@media only screen 
and (min-width : 321px) {
/* Styles */
}
@media only screen 
and (max-width : 320px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}
@media only screen 
and (min-width : 1224px) {
/* Styles */
}
@media only screen 
and (min-width : 1824px) {
/* Styles */
}

可以使用CSS
media querys
或像这样使用javascript来检测für移动设备:

@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
之后,使用isMobileDevice检查并删除模具图像,如:

var isMobileDevice      = false;

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
    isMobileDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|webOS)/);
}

在媒体查询中使用css代码

代码段将仅显示不小于769px的全宽结果。i、 例如,从平板电脑的大小

@介质(最小宽度:769px){
身体{
背景:url(http://www.psdgraphics.com/file/colorful-triangles-background.jpg),url(../img/background_rightside.png);
背景位置:左上、右上;
背景重复:重复-y;
背景附件:固定;
单词包装:打断单词;
}

}
媒体查询的唯一问题是,它们无法检测像小型平板电脑那样的小型桌面浏览器。因此,您需要一些js。您想检测移动设备还是要检测屏幕资源?第一个需要js,第二个需要媒体查询。