使用最大设备宽度和最大宽度的媒体查询冲突



我试图了解使用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) {...}

最大设备宽度是指设备的实际屏幕宽度

最大宽度是指视口宽度。

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

因此,如果您使用最大宽度,然后将浏览器窗口大小调整到狭窄的宽度,即降低视口宽度 - 您的移动规则将启动。

这应该是您想要的:

@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/

最新更新