All answers are incorrect. Android will swap from portrait to landscape when the keyboard is shown.
Different keyboards also need testing as they can take up more vertical space. Swift keyboard takes up more vertical space so you cannot use solutions like @media screen and (min-aspect-ratio: 13/9) { /* landscape styles here */}
as this will fail on lots of phones.
The only solution is to use javascript.
On newer Android devices you can test and use the new window.screen.orientation api.
On iOS you can use window.orientation which works fine. ie Math.abs( window.orientation ) === 90
is landscape
And as a fallback you can use window.screen.width > window.screen.height
which will cover really old Android devices which don't support the new window.screen.orientation api
Then all you need to do is add / remove a class on resize / orientationchange events.
/* Android Orientation */
var orientation = window.screen.orientation || window.screen.mozOrientation || window.screen.msOrientation || null;
/* Check */
if ( orientation && orientation.type ) {
/* Landscape */
if ( orientation.type === 'landscape' || orientation.type === 'landscape-primary' || orientation.type === 'landscape-secondary' ) {
return 'landscape';
/* Portrait */
} else {
return 'portrait';
}
}