Using Sass Variables with CSS3 Media Queries

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

    I had the same problem.

    The $menu-width variable should be 240px on the mobile view @media only screen and (max-width : 768px) and 340px on the desktop view.

    So i have simply created two variables:

    $menu-width: 340px;
    $menu-mobile-width: 240px;
    

    And here is how i have used it:

    .menu {
        width: $menu-width;
        @media only screen and (max-width : 768px) {
          width: $menu-mobile-width;
        }
    }
    

提交回复
热议问题