Fancy Media Queries with some LESS Magic

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

    I am using these mixins & variables

    .max(@max; @rules){@media only screen and (max-width: (@max - 1)){@rules();}}
    .min(@min; @rules){@media only screen and (min-width: @min){@rules();}}
    .bw(@min; @max; @rules){@media only screen and (min-width: @min) and (max-width: (@max - 1)){@rules();}}
    
    @pad: 480px;
    @tab: 800px;
    @desktop: 992px;
    @hd: 1200px;
    

    So this

    footer{
        width: 100%;
        .bw(@tab,@desktop,{
            width: 768px;
        });
        .min(@desktop,{
            width: 940px;
        });
    }
    

    becomes

    footer {
      width: 100%;
    }
    @media only screen and (min-width: 800px) and (max-width: 991px) {
      footer {
        width: 768px;
      }
    }
    @media only screen and (min-width: 992px) {
      footer {
        width: 940px;
      }
    }
    

提交回复
热议问题