媒体查询使用max-device-width和max-width冲突

时间:2014-03-06 09:02:07

标签: css css3 media-queries

我想了解使用max-device-width指定某个网站的某些元素对设备做出响应并使用max-width用于桌面之间是否存在任何冲突。我从论坛上听到,在您的样式表中使用device-width会在您的设备上为您提供不同的布局?

在被覆盖的意义上是否会有任何冲突?

这是我到目前为止所做的:

/* Desktops and laptops ----------- */
@media only screen and (max-width : 1824px) {...}

/* iPads (landscape) ----------- */
@media only screen and (max-width : 1224px) {...}

/* iPads (portrait) ----------- */
@media only screen and (max-width : 1024px) {...}

/* Smartphones (landscape) ----------- */
@media only screen and (max-width : 768px) {...}

/* Big smartphones (portrait)*/
@media only screen and (max-width : 640px) {...}

/* Big smartphones (portrait)*/
@media only screen and (max-width : 480px) {...}

/* Smartphones (portrait) */
@media only screen and (max-width : 321px) {...}


/* Only iPhone 4 ----------- */
@media only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* YOUR STYLE GOES HERE */
}


/* Smartphones (portrait) */
@media only screen and (max-device-width : 768px) {...}

2 个答案:

答案 0 :(得分:1)

max-device-width指设备的实际屏幕宽度

max-width指视口宽度。

当视口宽度可变时,它们只会相互冲突。

因此,如果您使用max-width,然后将浏览器窗口的大小调整为较窄的宽度,即缩小视口宽度,那么您的移动规则将会启动。

答案 1 :(得分:1)

这应该是你想要的:

@media only screen and (min-width: 320px) {

  /* Small screen, non-retina */

}

@media
only screen and (-webkit-min-device-pixel-ratio: 2)      and (min-width: 320px),
only screen and (   min--moz-device-pixel-ratio: 2)      and (min-width: 320px),
only screen and (     -o-min-device-pixel-ratio: 2/1)    and (min-width: 320px),
only screen and (        min-device-pixel-ratio: 2)      and (min-width: 320px),
only screen and (                min-resolution: 192dpi) and (min-width: 320px),
only screen and (                min-resolution: 2dppx)  and (min-width: 320px) { 

  /* Small screen, retina, stuff to override above media query */

}

@media only screen and (min-width: 700px) {

  /* Medium screen, non-retina */

}

@media
only screen and (-webkit-min-device-pixel-ratio: 2)      and (min-width: 700px),
only screen and (   min--moz-device-pixel-ratio: 2)      and (min-width: 700px),
only screen and (     -o-min-device-pixel-ratio: 2/1)    and (min-width: 700px),
only screen and (        min-device-pixel-ratio: 2)      and (min-width: 700px),
only screen and (                min-resolution: 192dpi) and (min-width: 700px),
only screen and (                min-resolution: 2dppx)  and (min-width: 700px) { 

  /* Medium screen, retina, stuff to override above media query */

}

@media only screen and (min-width: 1300px) {

  /* Large screen, non-retina */

}

@media
only screen and (-webkit-min-device-pixel-ratio: 2)      and (min-width: 1300px),
only screen and (   min--moz-device-pixel-ratio: 2)      and (min-width: 1300px),
only screen and (     -o-min-device-pixel-ratio: 2/1)    and (min-width: 1300px),
only screen and (        min-device-pixel-ratio: 2)      and (min-width: 1300px),
only screen and (                min-resolution: 192dpi) and (min-width: 1300px),
only screen and (                min-resolution: 2dppx)  and (min-width: 1300px) { 

  /* Large screen, retina, stuff to override above media query */

}

像素密度设备列表:http://bjango.com/articles/min-device-pixel-ratio/