Fancy Media Queries with some LESS Magic

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

    +1 for Nguyen and Yancey - and one more addition.

    If you want explicit definition of the widths, you can accomplish that with string interpolation and variables for your breakpoints. Here for example with those of bootstrap - the strict rules are to prevent definition overlapping.

    @screen-xs-min:     480px;
    @screen-sm-min:     768px;
    @screen-md-min:     992px;
    @screen-lg-min:     1200px;
    
    @screen-xs-max:     (@screen-sm-min - 1);
    @screen-sm-max:     (@screen-md-min - 1);
    @screen-md-max:     (@screen-lg-min - 1);
    
    @phone:             ~"only screen and (max-width: @{screen-xs-min})";
    @phone-strict:      ~"only screen and (min-width: @{screen-xs-min}) and (max-width: @{screen-xs-max})";
    @tablet:            ~"only screen and (min-width: @{screen-sm-min})";
    @tablet-strict:     ~"only screen and (min-width: @{screen-sm-min}) and (max-width: @{screen-sm-max})";
    @desktop:           ~"only screen and (min-width: @{screen-md-min})";
    @desktop-strict:    ~"only screen and (min-width: @{screen-md-min}) and (max-width: @{screen-md-max})";
    @large:             ~"only screen and (min-width: @{screen-lg-min})";
    
    footer{
        width: 100%;
        @media @tablet {
            width: 768px;
        }
        @media @desktop {
            width: 940px;
        }
    }
    

提交回复
热议问题