russellsayshi russellsayshi - 3 months ago 69
CSS Question

Media Queries - In between two widths

I'm trying to use CSS3 media queries to make a class that only appears when the width is greater than 400px and less than 900px. I know this is probably extremely simple and I am missing something obvious, but I can't figure it out. What I have come up with is the below code, appreciate any help.

@media (max-width:400px) and (min-width:900px) {
.class {
display: none;
}
}

Answer

You need to switch your values:

/* No greater than 900px, no less than 400px */
@media (max-width:900px) and (min-width:400px) {
    .foo {
        display:none;
    }
}‚Äč

Demo: http://jsfiddle.net/xf6gA/ (using background color, so it's easier to confirm)