16

I am trying to set different media queries for smartphone orientation and desktop, i want to target portrait and landscape. I am aware of all the other stack links such has:

Media query to target most of smartphone 3 media queries for iphone portrait, landscape and ipad portrait

But I am still having issues, my landscape one isn't working, this is the code I am using:

Desktop css first
   -- css for desk --

Portrait:

   @media only screen 
     and (min-device-width: 320px) 
     and (max-device-width: 479px) {

}

Landscape:

   @media only screen 
     and (min-device-width: 480px) 
     and (max-device-width: 640px) {

}

The landscape code is like not even getting considered

rob.m
  • 9,843
  • 19
  • 73
  • 162

2 Answers2

33

Try adding

orientation : landscape

@media only screen and (min-device-width: 480px) 
                   and (max-device-width: 640px) 
                   and (orientation: landscape) {

//enter code here
}

See this site or this snippet for reference.

Siva-Dev-Wizard
  • 127
  • 1
  • 10
Danield
  • 121,619
  • 37
  • 226
  • 255
9

It's better to tackle the height than the width since the width has a large amplitude of sizes while 575.98px for mobile is, at least for now, a range that covers a LOT of devices.

@media only screen and (max-height: 575.98px) and (orientation: landscape) {
//enter code here
}
Luis Alves
  • 1,315
  • 1
  • 10
  • 16