orientation - CSS: Cascading Style Sheets 编辑
The orientation
CSS media feature can be used to test 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.
Syntax
The orientation
feature is specified as a keyword value chosen from the list below.
Keyword values
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.
Examples
HTML
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
CSS
body {
display: flex;
}
div {
background: yellow;
}
@media (orientation: landscape) {
body {
flex-direction: row;
}
}
@media (orientation: portrait) {
body {
flex-direction: column;
}
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
Media Queries Level 4 The definition of 'orientation' in that specification. | Candidate Recommendation | No change. |
Media Queries The definition of 'orientation' in that specification. | Recommendation | Initial definition. |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论