css - 媒体查询相互覆盖 - 奇怪的情况

标签 css media-queries

我的 iPhoneX 媒体查询覆盖了我所有的其他媒体查询。我的所有其他媒体查询都使用最小/最大宽度接受它们对应的屏幕尺寸。但出于某种原因,IphoneX 使所有其他媒体查询无效。谁能帮忙?

/* images */

img{
    max-width: 250px;
    width: 100%;
  }

  /* Header image */

  .headerImg{
    max-width: 250px;
    margin: 0 auto;
    padding-top: 10px;
  }

  /* Title */

  .title{
    max-width: 250px;
    margin: 0 auto;
    padding-top: 20px;
  }

  /* voting buttons */

  .vote{
    position:relative;
    text-align: center;
    padding-top: 20px;
  }

  #vote1 .dot{
    width: 13px;
    height: 13px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    top: 28px;
    left: 15px;
    border: 2px solid white;
  }

  #vote2 .dot{
    width: 13px;
    height: 13px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    top: 30px;
    left: 24px;
    border: 2px solid white;
  }

  /* GLOBAL CLASSES */

  .flexCenter{
     display: flex;
     justify-content: center;
     align-items: center;
  }

  .paddingTopBottom{
     padding: 10px 0;
  }

<!-- iPhone4/4s -->
<link href="https://pub.s6.exacttarget.com/vaf4d25yesa" rel="stylesheet" media="screen and (min-device-width: 320px) and (max-device-width: 480px)">  
<!-- iPhone5s/5c/5se -->
<link href="https://pub.s6.exacttarget.com/asgp1bospyf" rel="stylesheet" media="screen and (min-device-width: 320px) and (max-device-width: 568px)">  
<!-- iPhone6/6s/7/8 -->
<link href="https://pub.s6.exacttarget.com/c3c1pf4b2me" rel="stylesheet" media="screen and (min-device-width: 375px) and (max-device-width: 667px)">
<!-- iPhone6+/7+/8+ -->
<link href="https://pub.s6.exacttarget.com/qjhe5zmjrys" rel="stylesheet" media="screen and (min-device-width: 414px) and (max-device-width: 736px)">
<!-- iPhoneX -->
<link href="https://pub.s6.exacttarget.com/ioeyyyvvogl" rel="stylesheet" media="screen and (min-device-width: 375px) and (max-device-width: 812px)">

这是链接的媒体查询。

/* Media queries for mobile sizes */

/* ----------- iPhone X ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) { 
    .headerImg{max-width: 280px !important;padding-top: 50px !important}
    .title{max-width: 280px !important;padding-bottom: 50px !important;padding-top: 25px !important;}
    .deal{max-width: 115px !important;}
    .vote {padding-top: 0 !important;}
    #vote1 .dot {top: 11px !important;left: 15px !important;}
    #vote2 .dot {top: 11px !important;left: 9px !important;}
    .smartcapture-submit-button-wrapper{bottom: 120px !important;}
    .sc-button{height: 45px !important; width: 160px !important;}
}

/* ----------- iPhone 6+, 7+ and 8+ ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 414px) and (max-device-width: 736px) { 
    .headerImg{max-width: 280px !important;padding-top: 20px !important}
    .title{max-width: 280px !important;padding-bottom: 40px !important;}
    .deal{max-width: 115px !important;}
    .vote {padding-top: 0 !important;}
    #vote1 .dot {top: 13px !important;left: 17px !important;}
    #vote2 .dot {top: 13px !important;left: 11px !important;}
    .smartcapture-submit-button-wrapper{bottom: 80px !important;}
    .sc-button{height: 45px !important; width: 160px !important;}
}

/* ----------- iPhone 6, 6S, 7 and 8 ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) { 
    .headerImg{max-width: 280px !important;padding-top: 20px !important}
    .title{max-width: 280px !important;padding: 10px 0 !important;}
    .deal{max-width: 115px !important;}
    .vote {padding-top: 0 !important;}
    #vote1 .dot {top: 11px !important;left: 15px !important;}
    #vote2 .dot {top: 11px !important;left: 9px !important;}
    .smartcapture-submit-button-wrapper{bottom: 80px !important;}
    .sc-button{height: 45px !important; width: 160px !important;}
}

/* ----------- iPhone 5, 5S, 5C and 5SE ----------- */

/* Portrait and Landscape */
@media only screen and (min-device-width: 320px) and (max-device-width: 568px) {
    .headerImg{max-width: 200px !important;padding-top: 20px !important}
    .title{max-width: 200px !important;padding: 10px 0 !important;}
    .deal{max-width: 100px !important;}
    .vote {padding-top: 0 !important;}
    #vote1 .dot {top: 7px !important;left: 15px !important;}
    #vote2 .dot {top: 7px !important;left: 9px !important;}
    .smartcapture-submit-button-wrapper{bottom: 60px !important;}
}

/* ----------- iPhone 4 and 4S ----------- */

@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
    .headerImg{max-width: 170px !important;}
    .title{max-width: 160px !important;padding: 10px 0 !important;}
    .deal{max-width: 110px !important;}
    .vote {padding-top: 0 !important;}
    #vote1 .dot {top: 7px !important;left: 15px !important;}
    #vote2 .dot {top: 7px !important;left: 9px !important;}
    .smartcapture-submit-button-wrapper{bottom: 60px !important;}
}

/* ----------- Galaxy S4, S5 and Note 3 ----------- */

/* Portrait and Landscape */
@media screen and (device-width: 320px) and (device-height: 640px) and {
    .headerImg{max-width: 240px !important;padding-top: 50px !important}
    .title{max-width: 240px !important;padding-bottom: 40px !important;padding-top: 15px !important;}
    .deal{max-width: 115px !important;}
    .vote {padding-top: 0 !important;}
    #vote1 .dot {top: 9px !important;left: 15px !important;width: 10px !important;; height: 10px !important;}
    #vote2 .dot {top: 9px !important;left: 9px !important;width: 10px !important;; height: 10px !important;}
    .smartcapture-submit-button-wrapper{bottom: 90px !important;}
    .sc-button{height: 45px !important; width: 160px !important;}
}

当我从媒体查询中删除 !important 时,没有选择任何样式,而是仅选择默认样式。

非常感谢任何帮助。

谢谢

最佳答案

伊莱纳

媒体查询可能很棘手...

如果您在 iPhone 6,7&8 媒体查询语句下方有 iPhone 4 媒体查询语句,它将(实际上)覆盖 iPhone 6,7&8,因为它列在它下面。 CSS 文件从上到下读取。例如:

<style>
.className {
  width: 50%;
}
.className {
  width: 100%;
}
</style>

宽度为 100% 的第二个 .className 将占用,因为它是最后一个(从上到下读取)。

它被覆盖的另一个原因是 iPhone 4 媒体查询的范围是 320px 到 480px,而 iPhone 6,7&8 的媒体查询范围在 iPhone 4 的范围内(375px 到 667px)。 375 到 480px 属于 iPhone 4 的范围...并且由于它低于 iPhone 6,7&8 的代码,因此优先...

此外,不确定为什么您有如此多的 !important 调用 - 如果您提供整个 css 文件以了解您的 ID 和类的顺序,可能会帮助我们更好地了解您的特定情况。

您是否尝试过将 iPhone 4 的媒体查询代码置于 iPhone 6、7 和 8 之上?如果是这样,您是否遇到同样的问题?

关于css - 媒体查询相互覆盖 - 奇怪的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54527612/

相关文章:

javascript - 在 Active 上使用减号启动 Bootstrap Accordion

css - Bootstrap 响应式水平布局 - 确定流程?

css - 最大宽度 241px 不适用于最小的浏览器尺寸

javascript - max-device-width 是指 document.body.clientWidth 吗?

javascript - 为什么使用 css3-mediaqueries.js 时我的 100% 宽元素会变成 30000px+ 宽?

html - 在 bootstrap 3 中排序类

internet-explorer - 什么会导致响应式网站默认为移动设备?

html - 表格的第一列尽可能宽,其他列等宽

html - iphone6 上的电子邮件应用程序测试

css - 如何导入没有默认类名的 Ant Design 组件?