媒体查询无法正常工作 [英] media query not working as expected

查看:81
本文介绍了媒体查询无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么此代码使两个div都出现在面向景观的iPad上?

why does this code make both divs appear on a landscape-oriented iPad?

/* CSS */

div{
    display:none;   
}
@media screen and (min-width: 48em) {
  /* IPAD PORTRAIT */
  body {
      /* DARK BLUE */
   background-color:#006;
  }
    div{
    display:none;  
  }
    #ipad-portrait{
    display:block;  
  }
}


@media screen and (min-width: 64em) {
  /* IPAD LANDSCAPE */
  body{
      /*bright green*/
    background-color:#3f0;  
  }


  /* an attempt to hide all divs before displaying 
     the one that says iPad landscape */
  div{
    display:none;  
  }



  #ipad-landscape{
    display:block; 
  }
}



<!-- HTML -->
 <div id="ipad-landscape">
 ipad landscape
 </div>

  <div id="ipad-portrait">
 ipad portrait
 </div>

谢谢!

推荐答案

您的最小宽度重叠.最小宽度为64em的设备也最小宽度为48em.您可能想要的是这样的东西:

Your min-widths overlap. A device that is a minimum of 64em wide is also a minimum of 48em wide. What you might be wanting is something like this:

@media screen and (min-width: 48em) and (max-width: 63.999em) {
/* stuff */
}

这篇关于媒体查询无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆