Fancy Media Queries with some LESS Magic

后端 未结 8 1397
别跟我提以往
别跟我提以往 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 05:58

    Here is what I've done in my projects:

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

    This allows you to only define your media queries once and you can use it throughout your less files. Also a little easier to read. :)

提交回复
热议问题