Add class or other attribute using media query

前端 未结 5 1169
时光取名叫无心
时光取名叫无心 2021-02-13 18:22

I\'m currently using CSS media queries to target some small/medium screen devices like this:

@media screen and (min-device-width: 480px) {
  ...
}
@media screen          


        
5条回答
  •  遥遥无期
    2021-02-13 18:36

    It cannot be done with plain CSS.

    Have a look at LESS or SASS. They are designed to make working with CSS more dynamic and flexible.

    • http://lesscss.org
    • http://sass-lang.com

    Once you use them. You can't live without them.


    In case you want to add a existing class selector to the body on certain resolutions.

    SASS

    .some-style { background-color:red; }
    
    @media screen and (min-device-width: 480px) {
        body {
            @extend .some-style;
        }
    }
    

提交回复
热议问题