Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional media queries

I need to resize and hide an element based on certain conditions, but I can't get it right.

Pseduo code:

If height is less than or equal to 400px : hide
If height is between 401-600 : do x
If height is greater than or equal to 601px : do y

I'm doing this:

@media only screen and (max-height: 400px) {
    /* hide */
}
@media only screen and (min-height: 401px) and (max-height: 600px) {
    /* do X */
}
@media only screen and (max-height: 601px) {
    /* do Y */
}

...but it always defaults to the last condition: do Y

like image 779
eozzy Avatar asked Feb 13 '26 08:02

eozzy


1 Answers

Your last condition should be min-height and not max-height. also does not need to set and (max-height: 600px) because the following MQ will match anyway

http://jsfiddle.net/rnrlabs/3r382qts/

@media only screen and (max-height: 100px) {
    .condition {
        display: none;
        visibility: hidden;
    }
}
@media only screen and (min-height: 101px)  {
    .condition {
        color: red;
    }
}
@media only screen and (min-height: 301px) {
    .condition {
        color: blue;
    }
}
like image 147
rnrneverdies Avatar answered Feb 22 '26 03:02

rnrneverdies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!