blob: d55e57ccb2768fe96a622b6392b051a15a4bb6ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
---
title: orientation
slug: Web/CSS/@media/orientation
tags:
- '@media'
- CSS
- 参考
translation_of: Web/CSS/@media/orientation
---
<div>{{cssref}}</div>
<p><a href="/zh-CN/docs/CSS">CSS</a> <a href="/zh-CN/docs/Web/CSS/Media_Queries/Using_media_queries#Media_features">媒体属性</a><strong>屏幕方向</strong>(<strong><code>orientation</code></strong>)可用于测试视口 {{glossary("viewport")}}(或者对于<a href="/zh-CN/docs/Web/CSS/Paged_media">分页媒体</a>而言的页面框盒)的横纵方向。</p>
<div class="note">
<p><strong>注意:</strong>此属性不等价于<span class="syntaxbox"><em>设备</em></span>的屏幕旋转方向。在许多设备上,当屏幕方向为纵向时,打开软键盘将导致视口 viewport 的宽度大于高度,从而导致浏览器突然改用横向样式,而不是保持纵向。</p>
</div>
<h2 id="语法">语法</h2>
<p><code>orientation</code> 属性被指定为下列关键字值中的任意一个。</p>
<h3 id="关键字值">关键字值</h3>
<dl>
<dt><code>portrait</code></dt>
<dd>viewport 处于纵向,即高度大于等于宽度。</dd>
<dt><code>landscape</code></dt>
<dd>viewport 处于横向,即宽度大于高度。</dd>
</dl>
<h2 id="例子">例子</h2>
<h3 id="HTML">HTML</h3>
<pre class="brush: html"><div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
</pre>
<h3 id="CSS">CSS</h3>
<pre class="brush: css">body {
display: flex;
}
div {
background: yellow;
}
@media (orientation: landscape) {
body {
flex-direction: row;
}
}
@media (orientation: portrait) {
body {
flex-direction: column;
}
}</pre>
<h3 id="结果">结果</h3>
<p>{{EmbedLiveSample("Example")}}</p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('CSS4 Media Queries', '#orientation', 'orientation')}}</td>
<td>{{Spec2('CSS4 Media Queries')}}</td>
<td>No change.</td>
</tr>
<tr>
<td>{{SpecName('CSS3 Media Queries', '#orientation', 'orientation')}}</td>
<td>{{Spec2('CSS3 Media Queries')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("css.at-rules.media.orientation")}}</p>
|