css - 媒体查询冲突

标签 css media-queries

我的目标是解决网站内容与 WordPress 中的背景 slider (插件)重叠的问题。下面的媒体查询在设备之间存在冲突。如果它适用于移动设备,那么它会在 iPad 或任何横向模式上产生问题。

这是我的 CSS 媒体查询。

/*------ MEDIA QUERIES------ */


/* Iphone 6,7 Portrait */

@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation: portrait) and (-webkit-min-device-pixel-ratio: 2) {
  .HomePageBody {
    margin-top: -970px !important;
  }
  .nivoSlider {
    top: 40px;
    /*    position:absolute; */
    min-height: 500px !important;
    width: 100%;
    overflow: hidden;
  }
  /*      .site-content {   
      margin-top:-320px 
        }        */
}


/* Iphone 6,7 Landscape */

@media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (orientation: landscape) and (-webkit-min-device-pixel-ratio: 2) {
  .HomePageBody {
    margin-top: -110px !important;
  }
  .nivoSlider {
    top: 40px;
    /*   position:absolute; */
    min-height: 500px !important;
    width: 100%;
    overflow: hidden;
  }
  .site-content {
    margin-top: -320px !important;
  }
}

最佳答案

由于 min/max-device-width 已弃用,您可以使用 orientation纵向和横向查询。 所以你的代码将是这样的:

@media (orientation: landscape) {
...
}

@media (orientation: portrait) {
...
}

关于css - 媒体查询冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57011056/

相关文章:

html - Angular : is it possible to bind value of attribute to other html attribute

css - div高度问题

javascript - 获取 css 最高值作为数字而不是字符串?

javascript - JQuery 调用基于 CSS 属性的点击

CSS 媒体查询和屏幕分辨率

css - 媒体查询会影响 CSS 中的优先级吗?或者为什么会这样?

html - 同时定位超链接和表格

css - 没有媒体类型的@media 规则是做什么的?

@media 查询中的 LESS 变量

javascript - 我们怎样才能防止一个 block 被打印在不同的页面上