Multiple two-class selectors in Sass

后端 未结 4 1905
盖世英雄少女心
盖世英雄少女心 2021-01-31 13:59

Having multiple two-class selectors for a single declaration block, is it possible to simplify the following (i.e. not having to repeat the body tag):



        
相关标签:
4条回答
  • 2021-01-31 14:32

    In this case we can use @each directive:

    $pages: shop, contact, about, faq;
    
    body {
      @each $page in $pages {
        &.#{$page} {
          background-color:#FFF;
        }
      }
    }
    

    sassmeister.com

    0 讨论(0)
  • 2021-01-31 14:33
    body {
        &.shop, &.contact {
            // Styles here...
        }
    }
    
    0 讨论(0)
  • 2021-01-31 14:35

    try this:

    body{
       &.shop, &.contact, &.about, &.faq {
            background-color:#fff;
        }
    }
    
    0 讨论(0)
  • 2021-01-31 14:41

    If you are using sass compiled by the node, that may do.

        body {
          .shop, .contact, .about, .faq {
              background-color:#FFFFFF;
          }
        }
    
    0 讨论(0)
提交回复
热议问题