The orientation
CSS @media
media feature can be used to apply styles based on the orientation of the viewport (or the page box, for paged media).
Note: This feature does not correspond to device orientation. Opening the soft keyboard on many devices in portrait orientation will cause the viewport to become wider than it is tall, thereby causing the browser to use landscape styles instead of portrait.
The orientation
feature is specified as a keyword value chosen from the list below.
portrait
landscape
<div>Box 1</div> <div>Box 2</div> <div>Box 3</div>
body { display: flex; } div { background: yellow; } @media screen and (orientation: landscape) { body { flex-direction: row; } } @media screen and (orientation: portrait) { body { flex-direction: column; } }
Specification | Status | Comment |
---|---|---|
Media Queries Level 4 The definition of 'orientation' in that specification. | Working Draft | No change. |
Media Queries The definition of 'orientation' in that specification. | Recommendation | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@media/orientation