Using Sass Variables with CSS3 Media Queries

后端 未结 7 2216
醉话见心
醉话见心 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

    Edit: Please do not use this solution. The answer by ronen is much better.

    As a DRY solution, you can use the @import statement inside a media query, e.g. like this.

    @media screen and (max-width: 1170px) {
        $base_width: 960px;
        @import "responsive_elements";
    }
    @media screen and (min-width: 1171px) {
        $base_width: 1160px;
        @import "responsive_elements";
    }
    

    You define all responsive elements in the file included using the variables defined in the media query. So, all you need to repeat is the import statement.

提交回复
热议问题