/
index.md
372 lines (338 loc) · 9.27 KB
/
index.md
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
---
title: page-orientation
slug: Web/CSS/@page/page-orientation
page-type: css-at-rule-descriptor
browser-compat: css.at-rules.page.page-orientation
---
{{CSSRef}}
The **`page-orientation`** [CSS](/en-US/docs/Web/CSS) descriptor for the {{cssxref("@page")}} at-rule controls the rotation of a printed page. It handles the flow of content across pages when the orientation of a page is changed. This behavior differs from the [`size`](/en-US/docs/Web/CSS/@page/size) descriptor in that a user can define the direction in which to rotate the page.
This descriptor helps with the layout and orientation of printed documents, especially when documents are printed double-sided. A user can specify how the pages will be rotated when printed. This is particularly useful to lay out content such as tables, which may be wider than the rest of the content, in a different orientation.
> **Note:** [Margin boxes](/en-US/docs/Web/CSS/@page#margin_at-rules) and other positional elements have no special interaction with this descriptor. Margins are laid out as normal in the unrotated page, then rotated along with everything else.
## Syntax
```css
/* Displays the print content in an upright position */
@page {
page-orientation: upright;
}
/* Displays the print content rotated counter-clockwise */
@page {
page-orientation: rotate-left;
}
/* Displays the print content rotated counter-clockwise */
@page {
page-orientation: rotate-right;
}
```
## Values
- `upright`
- : No orientation is applied and the page is laid out and formatted as normal.
- `rotate-left`
- : After a page is laid out, the page must be displayed rotated a quarter turn to the left (counter-clockwise).
- `rotate-right`
- : After the page is laid out, the page must be displayed rotated a quarter turn to the right (clockwise).
## Formal definition
{{cssinfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Rotating printed pages
This example shows how the contents of a print document can be rotated to suit the page content and the page position.
```html hidden
<fieldset id="printStyle">
<legend>
Click Print. The page will be laid out in the defined orientation.
</legend>
<button id="print">Print</button>
</fieldset>
<div id="print-area">
<section class="upright">
<h2>Section in Portrait/Upright</h2>
<p>This section will be printed in portrait and upright with:</p>
<pre>
.upright {
size: portrait;
page-orientation: upright;
}
</pre>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu
convallis ligula, tincidunt malesuada tortor. Ut ac turpis erat. Mauris
consequat, leo rhoncus venenatis elementum, sem nisl venenatis justo, non
mattis diam massa vitae dolor. Aenean ac dolor et leo laoreet tincidunt.
Suspendisse tempus risus nibh, a feugiat mauris pharetra a. Nulla mi dui,
scelerisque vitae sollicitudin nec, placerat eget purus. Vivamus enim
elit, scelerisque id venenatis eu, sodales vel leo. Quisque bibendum
feugiat diam, ut feugiat urna suscipit et. Nulla lacinia metus a nisi
volutpat interdum. Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Vestibulum vitae elit vel orci malesuada bibendum ut vitae enim. Ut
ultrices elit nec vestibulum blandit. In in eleifend dui. Nam nec aliquet
nunc. Praesent convallis ipsum sed fermentum scelerisque.
</p>
<p>
Praesent posuere, neque non fringilla ultricies, purus mi ullamcorper
velit, vitae egestas nisl eros at ex. Nulla sed viverra libero. Praesent
sed placerat magna, iaculis commodo lectus. Ut gravida ligula sed purus
molestie, in accumsan est eleifend. Etiam consectetur nulla pretium
blandit iaculis. Nunc semper libero ut mauris faucibus placerat. Cras ac
justo ac est laoreet sollicitudin. Aliquam vel sapien ut sapien vestibulum
dictum.
</p>
</section>
<section class="left">
<h2>Section in Landscape/Left</h2>
<p>This section will be printed in landscape and rotated left with:</p>
<pre>
.left {
size: landscape;
page-orientation: rotate-left;
}
</pre>
<table>
<thead>
<tr>
<th></th>
<th>100m</th>
<th>1500m</th>
<th>Hurdles</th>
<th>Long Jump</th>
<th>High Jump</th>
<th>Javelin</th>
<th>Discus</th>
</tr>
</thead>
<tbody>
<tr>
<th>Dave</th>
<td>9.65</td>
<td>3:49</td>
<td>12.64</td>
<td>8.54m</td>
<td>1.95m</td>
<td>56.65m</td>
<td>47.63m</td>
</tr>
<tr>
<th>Simon</th>
<td>9.87</td>
<td>3:52</td>
<td>11.89</td>
<td>8.16m</td>
<td>1.96m</td>
<td>59.03m</td>
<td>45.72m</td>
</tr>
<tr>
<th>Fred</th>
<td>9.67</td>
<td>3:52</td>
<td>12.03</td>
<td>8.04m</td>
<td>2.01m</td>
<td>62.58m</td>
<td>46.83m</td>
</tr>
<tr>
<th>Gary</th>
<td>9.77</td>
<td>3:56</td>
<td>13.04</td>
<td>7.96m</td>
<td>2.02m</td>
<td>63.87m</td>
<td>47.73m</td>
</tr>
<tr>
<th>Dick</th>
<td>9.95</td>
<td>3:44</td>
<td>12.99</td>
<td>5.66m</td>
<td>1.97m</td>
<td>56.43m</td>
<td>43.87m</td>
</tr>
<tr>
<th>Tom</th>
<td>9.84</td>
<td>3:48</td>
<td>12.86</td>
<td>6.87m</td>
<td>1.95m</td>
<td>67.03m</td>
<td>42.73m</td>
</tr>
<tr>
<th>Harry</th>
<td>9.91</td>
<td>3:53</td>
<td>13.77</td>
<td>7.34m</td>
<td>1.94m</td>
<td>62.84m</td>
<td>46.72m</td>
</tr>
</tbody>
</table>
</section>
<section class="right">
<h2>Section in Landscape/Right</h2>
<p>This section will be printed in landscape and rotated right with:</p>
<pre>
.right {
size: landscape;
page-orientation: rotate-right;
}
</pre>
<table>
<thead>
<tr>
<th></th>
<th>100m</th>
<th>1500m</th>
<th>Hurdles</th>
<th>Long Jump</th>
<th>High Jump</th>
<th>Javelin</th>
<th>Discus</th>
</tr>
</thead>
<tbody>
<tr>
<th>Dave</th>
<td>9.65</td>
<td>3:49</td>
<td>12.64</td>
<td>8.54m</td>
<td>1.95m</td>
<td>56.65m</td>
<td>47.63m</td>
</tr>
<tr>
<th>Simon</th>
<td>9.87</td>
<td>3:52</td>
<td>11.89</td>
<td>8.16m</td>
<td>1.96m</td>
<td>59.03m</td>
<td>45.72m</td>
</tr>
<tr>
<th>Fred</th>
<td>9.67</td>
<td>3:52</td>
<td>12.03</td>
<td>8.04m</td>
<td>2.01m</td>
<td>62.58m</td>
<td>46.83m</td>
</tr>
<tr>
<th>Gary</th>
<td>9.77</td>
<td>3:56</td>
<td>13.04</td>
<td>7.96m</td>
<td>2.02m</td>
<td>63.87m</td>
<td>47.73m</td>
</tr>
<tr>
<th>Dick</th>
<td>9.95</td>
<td>3:44</td>
<td>12.99</td>
<td>5.66m</td>
<td>1.97m</td>
<td>56.43m</td>
<td>43.87m</td>
</tr>
<tr>
<th>Tom</th>
<td>9.84</td>
<td>3:48</td>
<td>12.86</td>
<td>6.87m</td>
<td>1.95m</td>
<td>67.03m</td>
<td>42.73m</td>
</tr>
<tr>
<th>Harry</th>
<td>9.91</td>
<td>3:53</td>
<td>13.77</td>
<td>7.34m</td>
<td>1.94m</td>
<td>62.84m</td>
<td>46.72m</td>
</tr>
</tbody>
</table>
</section>
</div>
```
#### CSS
In this first part of the CSS code, [named pages](/en-US/docs/Web/CSS/@page#named_pages) are set up to define the direction in which to rotate the content.
```css
@page upright {
size: portrait;
page-orientation: upright;
}
@page left {
size: landscape;
page-orientation: rotate-left;
}
@page right {
size: landscape;
page-orientation: rotate-right;
}
```
```css hidden
fieldset {
display: flex;
flex-direction: row;
justify-content: space-between;
gap: 1rem;
width: fit-content;
}
p {
max-width: 60ch;
}
@media print {
fieldset {
display: none;
}
section {
font-family: Roboto;
font-size: 1.5rem;
}
}
```
The following second part of the CSS code declares a named page rule defined above for the selectors, such as `<section class="left">…</section>`.
```css
@media print {
.upright {
page: upright;
}
.left {
page: left;
}
.right {
page: right;
}
}
```
```js hidden
const printButton = document.querySelector("#print");
printButton.addEventListener("click", () => {
window.print();
});
```
### Result
Click the print button to see the pages rotated.
{{ EmbedLiveSample('Rotating_printed_pages', '100%', 520) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}