LESS: Can you group a CSS selector with a media query?

前端 未结 1 1929
北恋
北恋 2021-01-14 02:38

I really enjoyed finding out you could create a media query variable that you can easily reuse and makes your code much more readable.

@tablet: ~\"(min-width         


        
1条回答
  •  北海茫月
    2021-01-14 03:03

    I'm not a 100% certain of the output you are going for, but this LESS only defines the color red once, and applies it to both:

    @tablet: ~"(min-width: 768px) and (max-width: 980px)";
    body {
      aside { color: blue }
    
      &.homepage {
        aside { color: red }
      }
    
      @media @tablet {
        .homepage;
      }
    }
    

    Yields this CSS:

    body aside {
      color: #0000ff;
    }
    body.homepage aside {
      color: #ff0000;
    }
    @media (min-width: 768px) and (max-width: 980px) {
      body aside {
        color: #ff0000;
      }
    }
    

    0 讨论(0)
提交回复
热议问题