How to detect the device orientation using CSS media queries?
CSS to detect screen orientation:
@media screen and (orientation:portrait) { … }
@media screen and (orientation:landscape) { … }
The CSS definition of a media query is at http://www.w3.org/TR/css3-mediaqueries/#orientation
Mobile orientation change not applying CSS
My problem is related to the order of my CSS requests.
I used to define 'min-device-width'
before the rest.
@media
only screen and (min-device-width: 240px) and (max-device-width: 520px),
only screen and (min-width: 240px) and (max-width: 520px) { ... }
But if I define it last, it works.
@media
only screen and (min-width: 240px) and (max-width: 520px),
only screen and (min-device-width: 240px) and (max-device-width: 520px) { ... }
For more information about device-width:- check out this question
CSS Media Query Screen orientation issue
You aren't choosing an element to apply the background to
@media screen and (orientation:landscape)
{background:red;}
Should be something like:
@media screen and (max-device-width: 1000px)
and (orientation:landscape){
body {
background: red;
}
}
The max-device-width should make it ignore desktops, if you don't put device
in there, it will still affect desktops that have made their browser smaller.
Related Topics
Wobbly CSS Animation with Border-Radius in Internet Explorer
Is -Negative Margin or Padding Invalid CSS According to W3C
How to Add Multiple Linear-Gradients to a CSS Background
How to Wrap Long Words on Newline, and Avoid Horizontal Scroll Using CSS
Force Elements to Be Horizontally Aligned
Make CSS :Hover Only Affect Parent Element
iOS Safari Transition Transform Not Working
CSS Stretched Background Image
Change Colour Navbar Header Ionic 2
Animating a Smooth CSS Grid-Column Change
Simulating Color Stops in Gradients for Ie
ASP.NET MVC 4 Minification & Background Images
100% Width Div Gets Cut Off When I Scroll Right If My Browser Window Is Smaller Than Div's Content