Save media query in variable

后端 未结 2 1623
无人及你
无人及你 2021-01-14 00:48

Is it possible to save a media query as a variable?

This don\'t work:

$max: @media (max-width: 980px) and (min-width: 768px);

I\'m

2条回答
  •  一个人的身影
    2021-01-14 01:48

    Use something like this

      @mixin respondTo($media) {
        @if $media == smallScreen {
          @media only screen and (max-width: $screenSmall - 1) { @content; }
        } @else if $media == mediumScreen {
          @media only screen and (max-width: $screenMedium) and (min-width: $screenSmall) { @content; }
        } @else if $media == largeScreen {
          @media only screen and (min-width: $screenXlarge) { @content; }
        }
      }
    

    Then you can do something like the following:

    .products {
      @include respondTo(smallScreen) {
        width: 300px;
      }
    
      @include respondTo(mediumScreen) {
        width: 700px;
      }
    }
    

提交回复
热议问题