How bad is it in practice to over-nest selectors in SASS/SCSS?

前端 未结 6 2087
情话喂你
情话喂你 2020-12-30 02:25

I have a .scss file that, among other things contains this:

nav {
  font-size: 0;
  ul {
    margin: $padding/3;
  }
  li {
    z-index: 10;
    position: re         


        
6条回答
  •  攒了一身酷
    2020-12-30 03:19

    Just think about how you would want to write the actual css selector. Don't nest everything just because it is a child of the element.

    nav li ul li a { 
        /* over specific, confusing */
    }
    .sub-menu a {
        /* add a class to nested menus */
    }
    

    Once you start chaining that many selectors, it becomes a pain to override and can lead to specificity issues.

提交回复
热议问题