css - media-query specificity - why is the largest style used when using max-width media queries? -


i have following (simplified) example code: ( jsbin: http://jsbin.com/cisahilido/1/edit?html,css,output )

scss:

.container {   background: none; }  @media screen , (max-width: 480px) {   .container {     background: red;   } }  @media screen , (max-width: 768px) {     .container {     background: white;   } }  @media screen , (max-width: 1024px) {     .container {     background: blue;   } } 

markup:

<!doctype html> <html> <head>   <meta charset="utf-8">   <title>js bin</title> </head> <body>   <div class="container">     hello!   </div> </body> </html> 

now, when screen 480px or less, expect .container have red background. however, seems have blue background, until 1024px breakpoint, has no background.

why max-width styles override smaller breakpoints bigger ones?

because 480 less last max-width of 1024. css uses last valid value, need order max-width media queries largest smallest intended value.

jsbin

.container {     background: none; }  @media screen , (max-width: 1024px) {     .container {         background: blue;     } }  @media screen , (max-width: 768px) {     .container {         background: white;     } }  @media screen , (max-width: 480px) {     .container {         background: red;     } } 

Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -