【问题标题】:Why is my media query affecting every width and not just targeting the (max-width: 860px) which I set?为什么我的媒体查询会影响每个宽度,而不仅仅是针对我设置的 (max-width: 860px)?
【发布时间】:2020-09-26 18:30:28
【问题描述】:

我正在设计一个网站,并按照我的意愿拥有它,直到我添加了媒体查询...... 它只是一个针对 860 像素及以下设备的媒体查询(最大宽度:860 像素)...

然而媒体查询不知何故甚至在更宽的屏幕上生效,实际上弄乱了我的整个布局......我将它放在单独的 .css 文件中,因为我想检查如果我不链接一切看起来是否正常媒体查询 .css 文件 - 是的 - 没有它一切都很好......

我真的不明白是什么导致了媒体查询的行为如此。我在发布此问题之前进行了搜索,但找不到此特定问题。

请谁能帮我解决这个问题?这是我的 media.css -


@media (max-width: 860px) {

  .navbar span {
    display: none;
  }

  .navbar h2 {
    display: none;
  }
  .navbar img {
    width: 50px;
    /* padding: 0 15px; */
    display: flex;
    flex-direction: row;
  }

  .navbar {
    display: flex;
    justify-content: space-between;
  }

  .hide {
    display: none;
  }

  .section-1 {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
  }

  .mobile-img {
    display: block;
    width: 100%;
    margin-bottom: 0;
  }

  .section-1-content {
    display: block;
    width: 100%;
    margin: 0;
  }

  .section-1 h1 {
    font-size: 10vw;
    line-height: 10vw;
    margin-top: -8vw;
  }

  .section-1 p {
    font-size: 5vw;
    line-height: 6vw;
  }

  .section-1 .btn {
    background-color: #9b9b9b; 
    width: 100%;
  }

  .section-2-left {
    display: none;
  }

  .section-2 {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .section-2 .content-right {
    display: inline-block;
    width: 100%;
  }

  .box-side {
    display: block;
    border: none;
  }

  .section-2 .box-side-text {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .section-2 h4 {
    font-size: 5vw;
    padding-bottom: 2vw;
  }

  .section-2 p {
    font-size: 4vw;;
  }

  .section-2 a {
    font-size: 4vw;;
  }

  .section-3 h3 {
    font-size: 7vw;
    font-weight: 780;
  }

  .section-3 {
    /* display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%; */
  }

  /* .grid {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 90%; */

  }

  .box {
    display: flex;
    flex-direction: column;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;

  }

  .row-1, .row-2, .text-wrap-grid {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
  }

  .text-wrap-grid {
     background-color: #d8d8d8;

  }

    /* display: block; */
    /* display: flex;
    flex-direction: column;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;

   */

  .section-3 h4 {
    font-size: 3.5vw;
  }


  .section-4 h3 {
    font-size: 7vw;
    font-weight: 780;
  }

  .section-4-all {
    display: flex;
    flex-direction: column;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
  }

  .section-4-left {
    display: flex;
    flex-direction: column;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
  }


  video {
    width: 100%;
  }

}

【问题讨论】:

    标签: css responsive-design media-queries responsive


    【解决方案1】:

    我想通了 - 是的,这是愚蠢和愚蠢的,所以我收回我之前说的话。

    所以当我评论一些东西时 - 我不小心漏掉了几个 } 只是闲逛,这导致了错误......

    对不起...我已经研究了几个小时所以我一开始没有看到它

    【讨论】:

      【解决方案2】:

      这是因为您没有正确设置媒体查询。请尝试使用

      @media only screen and (max-width: 860px) {
      }
      

      看看这是否有效。

      【讨论】:

      • 设置正确 - 我已经多次使用这个版本(没有额外的规范),在这种情况下这不是问题......当然我在这里发布问题之前检查了添加规范- 并没有改变...
      • 我猜你在某个时候会丢失},即使你关闭了整个查询。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-19
      • 2022-01-17
      • 1970-01-01
      • 2023-03-19
      • 2020-11-26
      • 2011-11-09
      • 1970-01-01
      相关资源
      最近更新 更多