17

I want to write media query based on screen resolution. My screen resolution height is 768. I wrote media query for this as:

@media(min-height:768px) and (max-height:850px) {
   .video-contain{
     margin-top:110px;  
    }
}

My above media query is not working.margin-top is not set before. I wrote media query based for screen resolution but not browser height.

Mukesh Ram
  • 6,248
  • 4
  • 19
  • 37
user3386779
  • 6,883
  • 20
  • 66
  • 134

6 Answers6

19

Use:

@media screen and ( min-width: 850px ) and ( max-height: 768px )
{
   .video-contain{
     margin-top:110px;  
    }
}

NOTE: Always use max-width media queries to great effect.

4b0
  • 21,981
  • 30
  • 95
  • 142
Aditya Male
  • 236
  • 1
  • 3
  • 10
    "NOTE: Always use max-width media queries to great effect" Can you explain why ? – Tarik Merabet Mar 06 '20 at 15:08
  • I wouldn't recommend using max-width and max-height with multiple breakpoints, due to the fact that the size in media queries is specified in logical layout pixels and the device logical size can take floating point values. For example it can be 768.5px, which would be greater than the max-width and below the min-width at the same time, so no media query would be applied. Take a look at the example here: https://jsfiddle.net/lexkrstn/g2te9b89/ – Alexander Korostin Jul 23 '21 at 16:24
  • "Always use max-width media queries to great effect" I've always read that mobile up is the better approach. – Popnoodles Mar 05 '23 at 12:57
2

It seems like the issue is that your viewport is not the full resolution of your screen.

If you set the min-height to something lower, such as 720px, it ought to work.

 @media(min-height:720px) and (max-height:850px)
{
   .video-contain{
     margin-top:110px;
    }

 }
Judd Franklin
  • 570
  • 2
  • 5
  • 16
2

@media only screen and (max-width: 375px) and (max-height:667px) { }

isherwood
  • 58,414
  • 16
  • 114
  • 157
1

Please try this:

@media only screen and (min-width: 768px) and (max-width: 850px) {
}
Kashish Agarwal
  • 303
  • 1
  • 15
1
//simple max-width query
@media screen and ( min-height: 600px ){
    background: blue;
    ....
}

This might help you.

RRajani
  • 411
  • 3
  • 10
0

You can define as like this.

@media screen and (max-width: 1600px) and (max-height: 900px){
    //code here
}

@media screen and (max-width: 1600px) and (max-height: 1200px){
        //code here
}

Or avoid mentioning width

@media screen and (max-height: 1200px){
            //code here
}
CodeMonkey
  • 2,828
  • 1
  • 23
  • 32