Can I update SASS variables in Media Queries?

前端 未结 3 2063
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 17:40

Consider the following SASS code. I want to make sure that if the screen is above 1250px then the margin-top should be 750px and then

3条回答
  •  猫巷女王i
    2020-12-19 18:24

    I have tried this then i fixed my issue. It will calculate all media-breakpoint automatically by given rate (base-size/rate-size)

    
    $base-size: 16;
    $rate-size-xl: 24;
    
        // set default size for all cases;
        :root {
          --size: #{$base-size};
        }
    
        // if it's smaller then LG it will set size rate to 16/16;
        // example: if size set to 14px, it will be 14px * 16 / 16 = 14px
        @include media-breakpoint-down(lg) {
          :root {
            --size: #{$base-size};
          }
        }
    
        // if it is bigger then XL it will set size rate to 24/16;
        // example: if size set to 14px, it will be 14px * 24 / 16 = 21px
        @include media-breakpoint-up(xl) {
          :root {
            --size: #{$rate-size-xl};
          }
        }
    
    @function size($px) {
       @return calc(#{$px} / $base-size * var(--size));
    }
    
    div {
      font-size: size(14px);
      width: size(150px);
    }
    

提交回复
热议问题