【问题标题】:media queries for smartphone portrait, landscape and desktop?智能手机纵向、横向和桌面的媒体查询?
【发布时间】:2013-06-30 20:31:50
【问题描述】:

我正在尝试为智能手机方向和桌面设置不同的媒体查询,我想定位纵向和横向。我知道所有其他堆栈链接,例如:

Media query to target most of smartphone 3 media queries for iphone portrait, landscape and ipad portrait

但我仍然有问题,我的景观之一不工作,这是我正在使用的代码:

Desktop css first
   -- css for desk --

Portrait:

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

}

Landscape:

   @media only screen 
     and (min-device-width: 480px) 
     and (max-device-width: 640px) {

}

横向代码就像没有考虑过

【问题讨论】:

    标签: css media-queries


    【解决方案1】:

    尝试添加

    orientation : landscape
    
    @media only screen and (min-device-width: 480px) 
                       and (max-device-width: 640px) 
                       and (orientation: landscape) {
    
    //enter code here
    }
    

    请参阅 this sitethis snippet 以供参考。

    【讨论】:

    • 添加“和(方向:横向)”也会对桌面产生影响
    • 但是宽度声明会过滤掉桌面
    • 此媒体查询不针对横向宽度超过 480 像素的任何最新手机
    【解决方案2】:

    处理高度比处理宽度更好,因为宽度的大小幅度很大,而移动设备的 575.98px 至少目前是一个涵盖很多设备的范围。

    @media only screen and (max-height: 575.98px) and (orientation: landscape) {
    //enter code here
    }
    

    【讨论】:

    • 这最终对我有用。视口的高度是我试图解决的真正问题。
    猜你喜欢
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 2012-12-04
    相关资源
    最近更新 更多