Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media Queries: check min-height and min-width?

I am trying to change CSS on my page based on the min-height and min-width of the browser, so I am using this:

@media (min-height: 500px), (min-width: 580px) {
   /* CSS stuff */
}

But for some reason, this doesn't work. I can check for min-height and max-width (or vice versa) or for max-height and max-width at the same time, but checking for both min values doesn't seem to work.

I should specify this more: I want the browser to act if a min-height or a min-width becomes true. Using the and-operator will only work if both criteria are true.

Am I doing something wrong?

like image 967
The.Prophecy Avatar asked Nov 07 '13 13:11

The.Prophecy


People also ask

Is there a media query for height?

The height media query's value is usually the width media query value divided by the screen's aspect ratio. The height media query is always equal to document. documentElement. clientHeight.

How do you write height and width in media query?

Use a comma to specify two (or more) different rules: @media screen and (max-width: 995px), screen and (max-height: 700px) { ... } Commas are used to combine multiple media queries into a single rule. Each query in a comma-separated list is treated separately from the others.

How do you write a media query for maximum and minimum height?

“max-width and max-height media query” Code Answer's @media only screen and (max-width: 600px) {...} @media only screen and (min-width: 600px) {...} @media only screen and (max-width: 600px) and (min-width: 400px) {...}

How do you set a minimum height in media query?

If you set the min-height to something lower, such as 720px, it ought to work. Show activity on this post. //simple max-width query @media screen and ( min-height: 600px ){ background: blue; .... } This might help you.


3 Answers

Use and instead of a comma, like this:

@media (min-height: 500px) and (min-width: 580px) {
    /* CSS stuff */
}
like image 148
Alexandra Avatar answered Oct 07 '22 22:10

Alexandra


Have you added following meta tag in :

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Here is REf : http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-dont-forget-the-viewport-meta-tag/

After that use your media Query :

@media (min-height: 500px) and (min-width: 580px) {
    /* CSS stuff */
}

For media query details you can more info from http://stephen.io/mediaqueries/ for all iOS devices. If you have any other query let me know. Even you can get better idea from here http://webdesignerwall.com/tutorials/responsive-design-in-3-steps

like image 43
Divya Bhaloidiya Avatar answered Oct 07 '22 22:10

Divya Bhaloidiya


Use media query one inside other:

@media  screen and  (min-height: 40px)  {
   @media  screen and  (min-width: 50px)  {
    /*enter css here to apply for both condition*/
   }
}
like image 40
Igor Cube Avatar answered Oct 07 '22 21:10

Igor Cube