【问题标题】:media query for desktop and iPad landscape桌面和 iPad 横向的媒体查询
【发布时间】:2018-02-23 07:24:04
【问题描述】:

所以有两个div如下:

/*for ipad portrait and landscape*/
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
    .aclass {
        display: block;
        background-color: antiquewhite;
    }
    .bclass {
        display: none;
    }
}

/*for medium device*/
@media only screen 
and (min-width : 992px) 
and (max-width : 1200px) {
    .aclass {
        display: none;
    }
    .bclass {
        display: block;
        background-color: aquamarine;
    }
}
<div class="hidden-xs aclass">div 1</div>
<div class="hidden-xs bclass">div 2</div>

我希望aclass 仅应用于 ipad,bclass 应用于桌面等中型设备。由于min-width: 992px 而应用bclass 的Ipad 横向模式出现了问题,但我希望在此处应用aclass。我该如何解决这个问题?

【问题讨论】:

    标签: css responsive-design media-queries responsive


    【解决方案1】:

    您是否尝试过使用and (orientation: landscape)?这是一个媒体查询约束,仅当设备处于横向模式时才强制执行 CSS 规则。 orientation: portrait 的工作原理相同

    【讨论】:

    • 是的,我试过了。但这并不能阻止 bclass 被应用
    • 那么也许试试@Johannes 的解决方案并使用min-device-heightmax-device-height。然后结合直到它们起作用。
    • ipad 和台式机的设备高度相同,即 768 像素。无法区分。
    【解决方案2】:

    您还可以在媒体查询中使用max-height/min-height 和/或max-device-height/min-device-height,并将其与您现有的查询结合使用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-30
    • 2018-05-19
    • 2011-12-30
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    相关资源
    最近更新 更多