media query not working as expected

不打扰是莪最后的温柔 提交于 2019-12-24 07:56:42

问题


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>

Thanks!


回答1:


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 */
}


来源:https://stackoverflow.com/questions/12735236/media-query-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!