Using Sass Variables with CSS3 Media Queries

后端 未结 7 2234
醉话见心
醉话见心 2020-11-22 14:06

I\'m trying to combine the use of a Sass variable with @media queries as follows:

$base_width:1160px;

@media screen and (max-width: 1170px) {$base_width: 96         


        
7条回答
  •  醉话见心
    2020-11-22 14:51

    Similar to Philipp Zedler's answer, you can do it with a mixin. That lets you have everything in a single file if you want.

        @mixin styling($base-width) {
            // your SCSS here, e.g.
            #Contents {
                width: $base-width;
            }
        }
    
        @media screen and (max-width: 1170px) {
            @include styling($base-width: 960px);
        }
        @media screen and (min-width: 1171px) {
            @include styling($base-width: 1160px);
        }
    

提交回复
热议问题