【问题标题】:Why does my div class name in scss duplicate in css?为什么我在 scss 中的 div 类名在 css 中重复?
【发布时间】:2021-12-28 16:28:51
【问题描述】:

在scss中

@media (max-width:600px) {
        .f-nav {
              flex-wrap:wrap;
          }
      }

在css中

@media (max-width: 600px) {
  .f-nav .f-nav {
    -ms-flex-wrap: wrap;
        flex-wrap: wrap;
  }
}

它打破了我的导航栏。 提前谢谢你。

这是我的整个 scss 代码。

.f-nav {
    display:flex;
    justify-content:space-between;
    width:100%;
    height:100%;
    p {
        font-size:2rem;
        font-family:'Bebas Neue', sans-serif;
        margin-right:auto;
        padding-left:3rem;
    }
       li {
         display:inline-block;
         list-style:none;
        
       }
         a {
           display:inline-block;
           font-size:1.5rem;
           color:rgb(0, 0, 0);
           text-decoration:none;
           list-style:none;
           font-family:'Bebas Neue', sans-serif;
           padding:0 20px;
           margin-top:1.3rem;
         }
      @media (max-width:600px) {
        .f-nav {
              flex-wrap:wrap;
          }
      }
      
      @media (max-width:600px) {
          p {
              text-align:center;
              align-items:center;
              padding-left: 10rem;
          }
      }    
}

【问题讨论】:

  • 你能向我们展示更多你的 scss 吗?
  • @LSE 我编辑了它。

标签: html css web sass flexbox


【解决方案1】:

这是因为您的 SCSS 是嵌套的。
如果你剪掉不相关的部分,它看起来像这样:

.f-nav {
  
  /*  
   Omitted styles
  */

  @media (max-width:600px) {
    .f-nav {
      flex-wrap:wrap;
    }
  }
}

这应该可以解决它:
(你已经在.f-nav里面了,不用再写了)

.f-nav {
  
  /*  
   Omitted styles
  */

  @media (max-width:600px) {
    flex-wrap:wrap;
  }
}

此外,这只是个人喜好问题,但我喜欢在之后添加我的媒体查询,所以我不必滚动太多来了解正在发生的事情。
这是一个使用整个 scss 的示例:

.f-nav {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 100%;

  @media (max-width:600px) {
    flex-wrap: wrap;
  }

  p {
    font-size: 2rem;
    font-family: 'Bebas Neue', sans-serif;
    margin-right: auto;
    padding-left: 3rem;

    @media (max-width:600px) {
      text-align: center;
      align-items: center;
      padding-left: 10rem;
    }
  }

  li {
    display: inline-block;
    list-style: none;
  }

  a {
    display: inline-block;
    font-size: 1.5rem;
    color: rgb(0, 0, 0);
    text-decoration: none;
    list-style: none;
    font-family: 'Bebas Neue', sans-serif;
    padding: 0 20px;
    margin-top: 1.3rem;
  }
}

【讨论】:

  • 非常感谢!
  • @woopwoop 没问题。我用我将如何组织 scss 的示例更新了答案。如果您以相同的方式组织,可能会更容易理解。祝你好运!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
  • 2012-04-10
  • 1970-01-01
  • 2018-08-18
  • 2021-07-29
相关资源
最近更新 更多