orientation
CSS
media feature
can be used to test the orientation of the
viewport
(or the page box, for
paged media
).
注意: 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.
orientation
feature is specified as a keyword value chosen from the list below.
portrait
The viewport is in a portrait orientation, i.e., the height is greater than or equal to the width.
landscape
The viewport is in a landscape orientation, i.e., the width is greater than the height.
<div>Box 1</div> <div>Box 2</div> <div>Box 3</div>
body {
display: flex;
}
div {
background: yellow;
}
@media (orientation: landscape) {
body {
flex-direction: row;
}
}
@media (orientation: portrait) {
body {
flex-direction: column;
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Media Queries Level 4
The definition of 'orientation' in that specification. |
候选推荐 | 无变化。 |
|
Media Queries
The definition of 'orientation' in that specification. |
推荐 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
orientation
media feature
|
Chrome 完整支持 3 | Edge 完整支持 12 | Firefox 完整支持 2 | IE 完整支持 9 | Opera 完整支持 10.6 | Safari 完整支持 5 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 11 | Safari iOS 完整支持 4.2 | Samsung Internet Android 完整支持 1.0 |
完整支持