Using Sass Variables with CSS3 Media Queries

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

    With @ronen's great answer and a map, there's some real power available:

        @mixin styling($map) {
            .myDiv {
                background: map-get($map, 'foo');
                font-size: map-get($map, 'bar');
            }
        }
    
        @media (min-height: 500px) {
            @include styling((
                foo: green,
                bar: 50px
            ));
        }
    
        @media (min-height: 1000px) {
            @include styling((
                foo: red,
                bar: 100px
            ));
        }
    

    It's now possible to have lots more DRY media queries targeting .myDiv with a bunch of different values.


    Map docs: https://sass-lang.com/documentation/functions/map

    Example map usage: https://www.sitepoint.com/using-sass-maps/

提交回复
热议问题