How to detect the device orientation using CSS media queries?
In JavaScript the orientation mode can be detected using:
if (window.innerHeight > window.innerWidth) {
portrait = true;
} else {
portrait = false;
}
However, is there a way to detect the orientation using CSS only?
Eg. something like:
@media only screen and (width > height) { ... }
Solution 1:
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
Solution 2:
@media all and (orientation:portrait) {
/* Style adjustments for portrait mode goes here */
}
@media all and (orientation:landscape) {
/* Style adjustments for landscape mode goes here */
}
but it still looks like you have to experiment