Reset/remove CSS styles for element only

前端 未结 14 1065
长情又很酷
长情又很酷 2020-11-22 00:52

I\'m sure this must have been mentioned/asked before but have been searching for an age with no luck, my terminology must be wrong!

I vaguely remember a twee

14条回答
  •  感动是毒
    2020-11-22 01:14

    You mentioned mobile-first sites... For a responsive design, it's certainly possible to override small-screen styles with large-screen styles. But you might not need to.

    Try this:

    .thisClass {
        /* Rules for all window sizes. */
    }
    
    @media all and (max-width: 480px) {
        .thisClass {
            /* Rules for only small browser windows. */
        }
    }
    
    @media all and (min-width: 481px) and (max-width: 960px) {
        .thisClass {
            /* Rules for only medium browser windows. */
        }
    }
    
    @media all and (min-width: 961px) {
        .thisClass {
            /* Rules for only large browser windows. */
        }
    }
    

    Those media queries don't overlap, so their rules don't override each other. This makes it easier to maintain each set of styles separately.

提交回复
热议问题