【问题标题】:Media query is not working for 768px ipad portrait媒体查询不适用于 768px ipad 肖像
【发布时间】:2023-03-07 04:21:01
【问题描述】:

我的媒体查询不适用于 768 像素 ipad 肖像。

如果我更改为 min-width 效果很好,但在 桌面版本 或其他分辨率 超过 769px 时会影响尺寸/p>

@media only screen and (max-width: 768px) {
  .sidebar-container.pressed .content-container {
    width: 93% !important;
  }
}

有人可以解释一下,并帮助如何解决?我只想让它在 768px 上工作。

谢谢

【问题讨论】:

    标签: html css media-queries


    【解决方案1】:

    iPhone 6 媒体查询

    /* iPhone 6 in portrait & landscape */
    @media only screen 
    and (min-device-width : 375px) 
    and (max-device-width : 667px) { /* STYLES GO HERE */}
    
    /* iPhone 6 in landscape */
    @media only screen 
    and (min-device-width : 375px) 
    and (max-device-width : 667px) 
    and (orientation : landscape) { /* STYLES GO HERE */}
    
    /* iPhone 6 in portrait */
    @media only screen 
    and (min-device-width : 375px) 
    and (max-device-width : 667px) 
    and (orientation : portrait) { /* STYLES GO HERE */ }
    

    iPhone 6 Plus 媒体查询

    /* iPhone 6 Plus in portrait & landscape */
    @media only screen 
    and (min-device-width : 414px) 
    and (max-device-width : 736px) { /* STYLES GO HERE */}
    
    /* iPhone 6 Plus in landscape */
    @media only screen 
    and (min-device-width : 414px) 
    and (max-device-width : 736px) 
    and (orientation : landscape) { /* STYLES GO HERE */}
    
    /* iPhone 6 Plus in portrait */
    @media only screen 
    and (min-device-width : 414px) 
    and (max-device-width : 736px) 
    and (orientation : portrait) { /* STYLES GO HERE */ }
    

    iPhone 5 和 5S 媒体查询

    /* iPhone 5 & 5S in portrait & landscape */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 568px) { /* STYLES GO HERE */}
    
    /* iPhone 5 & 5S in landscape */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 568px) 
    and (orientation : landscape) { /* STYLES GO HERE */}
    
    /* iPhone 5 & 5S in portrait */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 568px) 
    and (orientation : portrait) { /* STYLES GO HERE */ }
    

    iPhone 2G、3G、4、4S 媒体查询 值得注意的是,这些媒体查询对于 iPod Touch 第 1-4 代也是相同的。

    /* iPhone 2G-4S in portrait & landscape */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) { /* STYLES GO HERE */}
    
    /* iPhone 2G-4S in landscape */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) 
    and (orientation : landscape) { /* STYLES GO HERE */}
    
    /* iPhone 2G-4S in portrait */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) 
    and (orientation : portrait) { /* STYLES GO HERE */ }
    

    iPad

    /* iPad in portrait & landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px)  { /* STYLES GO HERE */}
    
    /* iPad in landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape) { /* STYLES GO HERE */}
    
    /* iPad in portrait */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait) { /* STYLES GO HERE */ }
    

    iPad 3 和 4 媒体查询

    /* If you're looking to target only 3rd and 4th generation Retina iPads (or tablets with similar resolution) to add @2x graphics, or other features for the tablet's Retina display, use the following media queries. */
    
    /* Retina iPad in portrait & landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px)
    and (-webkit-min-device-pixel-ratio: 2) { /* STYLES GO HERE */}
    
    /* Retina iPad in landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape)
    and (-webkit-min-device-pixel-ratio: 2) { /* STYLES GO HERE */}
    
    /* Retina iPad in portrait */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait)
    and (-webkit-min-device-pixel-ratio: 2) { /* STYLES GO HERE */ }
    

    iPad 1 和 2 媒体查询

    /* If you're looking to supply different graphics or choose different typography for the lower resolution iPad display, the media queries below will work like a charm in your responsive design! */
    
    /* iPad 1 & 2 in portrait & landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (-webkit-min-device-pixel-ratio: 1){ /* STYLES GO HERE */}
    
    /* iPad 1 & 2 in landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape)
    and (-webkit-min-device-pixel-ratio: 1)  { /* STYLES GO HERE */}
    
    /* iPad 1 & 2 in portrait */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait) 
    and (-webkit-min-device-pixel-ratio: 1) { /* STYLES GO HERE */ }
    

    iPad mini

    /* iPad mini in portrait & landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px)
    and (-webkit-min-device-pixel-ratio: 1)  { /* STYLES GO HERE */}
    
    /* iPad mini in landscape */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape)
    and (-webkit-min-device-pixel-ratio: 1)  { /* STYLES GO HERE */}
    
    /* iPad mini in portrait */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait)
    and (-webkit-min-device-pixel-ratio: 1)  { /* STYLES GO HERE */ }
    

    来源: http://stephen.io/mediaqueries/#iPad

    【讨论】:

      【解决方案2】:

      对于纵向模式的 iPad,通常最好在媒体查询中更加具体,因此请尝试以下操作:

      @media only screen 
      and (min-device-width : 768px) 
      and (max-device-width : 1024px) 
      and (orientation : portrait) { 
          /* Styles Here */
      }
      

      这样,您可以定位屏幕宽度在768px1024px 之间的设备,这就是 iPad,然后您通过将方向指定为纵向来过滤您的目标。

      您可以尝试这样的事情 - 减少 max-width - 以最小化它可能影响的任何其他屏幕,但我没有尝试过,因此无法验证它是否有效。

      @media only screen 
      and (min-device-width : 768px) 
      and (max-device-width : 770px) 
      and (orientation : portrait) { 
          /* Styles Here */
      }
      

      【讨论】:

        猜你喜欢
        • 2013-01-26
        • 2018-12-30
        • 2013-09-18
        • 1970-01-01
        • 2017-07-30
        • 2020-01-20
        • 1970-01-01
        • 2019-01-21
        • 2018-05-12
        相关资源
        最近更新 更多