Fancy Media Queries with some LESS Magic

后端 未结 8 1436
别跟我提以往
别跟我提以往 2020-12-04 05:23

It would be nice to wrap css-styles for different resolutions within some css-classes using less.

I\'d like to do something like:

footer {
  width: 1         


        
8条回答
  •  心在旅途
    2020-12-04 06:18

    I completely agree with Hai Nguyen's answer (which has been accepted) but you can clean it up a bit more by doing something like this:

    @desktop:   ~"only screen and (min-width: 960px) and (max-width: 1199px)";
    @tablet:    ~"only screen and (min-width: 720px) and (max-width: 959px)";
    
    footer{
      width: 100%;
      @media @tablet {
        width: 768px;
      }
      @media @desktop {
        width: 940px;
      }
    }
    

    It's essentially the same thing but lets you nest your media queries inside of the original selector. It keeps all css for a specific element together and makes your styles much more modular (vs the split breakpoint approach).

提交回复
热议问题