【发布时间】:2015-12-22 07:58:30
【问题描述】:
在下面的代码示例中,有两个具有桌面和移动样式的立方体。 例如,在 iphone 上,立方体应该是绿色的,而在桌面上它应该是(并且是)红色的。 在我的 iPhone 上,纵向视图我什么都没有,在横向视图中,它是红色而不是绿色。 在 iPad 上也一样。 在 Google Chrome 开发者工具上,当我选择 Apple iPhone 5 Portrait 时,它不会在 Styles 中显示媒体查询,就好像它没有识别它一样。 我做错了什么?
/* for desktop */
@media only screen and (min-width: 400px) and (max-width: 767px) {
#block2 {width:100px;height:100px;background:red;}
}
/* for iPhone */
@media only screen and (min-device-width:320px) and (max-device-width: 767) {
#block2 {width:100px;height:100px;background:green;}
}
/* for desktop */
@media only screen and (min-width: 960px) and (max-width: 1024px) {
#block {width:100px;height:100px;background:red;}
}
/* for iPad */
@media only screen and (min-device-width:768px) and (max-device-width: 1024) {
#block {width:100px;height:100px;background:green;}
}
<div id="block"></div>
<div id="block2"></div>
【问题讨论】:
-
您没有指定
pxmax-device-width: 767和这里max-device-width: 1024。 -
谢谢,我现在觉得有点傻,不过谢谢!
-
没问题,这解决了您的问题吗?
-
它确实做到了,谢谢! :-)
-
好的@Ollie,如果您想标记为正确,我将其添加为答案。
标签: css iphone ipad media-queries device