【发布时间】:2017-03-23 05:48:30
【问题描述】:
我希望仅针对 iphone 4、5、6 和 6 plus 的 CSS 类 我用了这个article,但想知道我是否不能分解这个。事实上,在我看来,前 2 个设备目标(最小宽度 320/最大最大宽度 480 像素和 568 像素,我可以只使用最大的最大宽度并将它们融合到一个声明中。感觉我的代码不够干净,而是重复。
这是我当前的代码:
.example {
@media
//iphone 4
(min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait),
//iphone 5
(min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait),
//iphone 6
(min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait),
//iphone 6+
(min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {
color: yellow;
}
}
我可以将上面的代码转换/分解成下面的代码吗?
.example {
@media
//mix iphone 4 and 5
(min-device-width: 320px)
and (max-device-width: 568pxpx)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait),
//iphone 6
(min-device-width: 375px)
and (max-device-width: 667px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait),
//iphone 6+
(min-device-width: 414px)
and (max-device-width: 736px)
and (-webkit-min-device-pixel-ratio: 3)
and (orientation: portrait) {
color: red
}
}
这是否也意味着某些 android 设备,例如 the Samsung Galaxy 3 的宽度与 iphone 4 (320px) 相同,也会有我的类“示例”应用的红色?
【问题讨论】: