Skip to content

Commit 2b3eb64

Browse files
bsmthpepelsbey
andauthored
feat(css): Update live samples calling window.print(), add 'allow-modals' (#38232)
* feat(css): Update at_page example, add 'allow-modals' * feat(css): Update page-orientation example, add 'allow-modals' * feat(css): Update page prop example, add 'allow-modals' * feat(css): Update :first example, add 'allow-modals' * feat(css): use proper IDs for livesamples * Update files/en-us/web/css/@page/index.md Co-authored-by: Vadim Makeev <[email protected]> * Update files/en-us/web/css/@page/page-orientation/index.md Co-authored-by: Vadim Makeev <[email protected]> --------- Co-authored-by: Vadim Makeev <[email protected]>
1 parent f357338 commit 2b3eb64

File tree

4 files changed

+136
-196
lines changed

4 files changed

+136
-196
lines changed

files/en-us/web/css/@page/index.md

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -288,48 +288,38 @@ An example of this can be found on the [`page`](/en-US/docs/Web/CSS/page#example
288288
### Using the size property to change the page orientation
289289

290290
This example shows how to split the `<section>`s into individual pages in `landscape` format with each page having a 20% margin when printed.
291+
Clicking the print button will launch a print dialog with the HTML sections split into individual pages.
291292

292-
#### HTML
293-
294-
```html
295-
<button>Print Webpage</button>
293+
```html live-sample___page-size
294+
<button>Print page</button>
296295
<article>
297296
<section>
298-
<h2>Header</h2>
299-
<p>
300-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur
301-
facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi
302-
aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam
303-
velit.
304-
</p>
297+
<h2>Header one</h2>
298+
<p>Paragraph one.</p>
305299
</section>
306300
<section>
307-
<h2>Header</h2>
308-
<p>
309-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur
310-
facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi
311-
aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam
312-
velit.
313-
</p>
301+
<h2>Header two</h2>
302+
<p>Paragraph two.</p>
314303
</section>
315304
<section>
316-
<h2>Header</h2>
317-
<p>
318-
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur
319-
facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi
320-
aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam
321-
velit.
322-
</p>
305+
<h2>Header three</h2>
306+
<p>Paragraph three.</p>
323307
</section>
324308
</article>
325309
```
326310

327-
#### CSS
311+
```js live-sample___page-size
312+
const button = document.querySelector("button");
328313

329-
```css
314+
button.addEventListener("click", () => {
315+
window.print();
316+
});
317+
```
318+
319+
```css live-sample___page-size
330320
@page {
331321
size: landscape;
332-
margin: 20%;
322+
margin: 2cm;
333323
}
334324

335325
section {
@@ -344,7 +334,7 @@ section {
344334
}
345335
```
346336

347-
```css hidden
337+
```css hidden live-sample___page-size
348338
body {
349339
font-family: "Helvetica", sans-serif;
350340
background-color: silver;
@@ -364,30 +354,16 @@ section {
364354
print-color-adjust: exact;
365355
-webkit-print-color-adjust: exact;
366356
margin: 0 auto;
367-
margin-block-end: 1.5rem;
357+
margin-block-end: 1rem;
368358
border: 1px dashed;
369359
}
370360
```
371361

372-
#### JavaScript
373-
374-
```js
375-
const button = document.querySelector("button");
376-
377-
button.addEventListener("click", () => {
378-
window.print();
379-
});
380-
```
381-
382-
#### Result
383-
384-
Clicking the print button will launch a print dialog with the html sections split into individual pages.
385-
386-
{{EmbedLiveSample('Using the size property to change the page orientation', '100%', 520)}}
362+
{{EmbedLiveSample('page-size', '100%', '540', , , , , "allow-modals")}}
387363

388364
### @page pseudo-class examples
389365

390-
Please refer to the various [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) of `@page` for examples.
366+
See the various [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) of `@page` for examples.
391367

392368
- {{Cssxref(":blank")}}
393369
- {{Cssxref(":first")}}
@@ -404,8 +380,8 @@ Please refer to the various [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes)
404380

405381
## See also
406382

383+
- The {{cssxref("page")}} property
407384
- The `@page` [`size`](/en-US/docs/Web/CSS/@page/size) descriptor
408-
- The {{Cssxref("page")}} property
409-
- See the [\[META\] CSS Paged Media Module Level 3](https://bugzil.la/286443) ticket in Bugzilla for tracking progress on the subject (page-based counters, etc.)
410385
- [CSS paged media](/en-US/docs/Web/CSS/CSS_paged_media) module
411-
- [Paged.js: W3C paged media polyfill](https://pagedjs.org/documentation/1-the-big-picture/)
386+
- [Paged.js: W3C paged media polyfill](https://pagedjs.org/documentation/1-the-big-picture/) on pagedjs.org
387+
- [\[META\] CSS Paged Media Module Level 3](https://bugzil.la/286443) Bugzilla for tracking progress on the subject (page-based counters, etc.)

files/en-us/web/css/@page/page-orientation/index.md

Lines changed: 62 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,64 @@ This descriptor helps with the layout and orientation of printed documents, espe
5454
### Rotating printed pages
5555

5656
This example shows how the contents of a print document can be rotated to suit the page content and the page position.
57+
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.
58+
59+
```css live-sample___rotating-pages
60+
@page upright {
61+
size: portrait;
62+
page-orientation: upright;
63+
}
64+
65+
@page left {
66+
size: landscape;
67+
page-orientation: rotate-left;
68+
}
69+
70+
@page right {
71+
size: landscape;
72+
page-orientation: rotate-right;
73+
}
74+
```
75+
76+
```css hidden live-sample___rotating-pages
77+
fieldset {
78+
display: flex;
79+
flex-direction: row;
80+
justify-content: space-between;
81+
gap: 1rem;
82+
width: fit-content;
83+
}
84+
p {
85+
max-width: 60ch;
86+
}
87+
@media print {
88+
fieldset {
89+
display: none;
90+
}
91+
section {
92+
font-family: Roboto, sans-serif;
93+
font-size: 1.5rem;
94+
}
95+
}
96+
```
97+
98+
The second part of the CSS code declares a named page rule defined above for the selectors, such as `<section class="left">…</section>`.
5799

58-
```html hidden
100+
```css live-sample___rotating-pages
101+
@media print {
102+
.upright {
103+
page: upright;
104+
}
105+
.left {
106+
page: left;
107+
}
108+
.right {
109+
page: right;
110+
}
111+
}
112+
```
113+
114+
```html hidden live-sample___rotating-pages
59115
<fieldset id="printStyle">
60116
<legend>
61117
Click Print. The page will be laid out in the defined orientation.
@@ -72,29 +128,8 @@ This example shows how the contents of a print document can be rotated to suit t
72128
page-orientation: upright;
73129
}
74130
</pre>
75-
<p>
76-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu
77-
convallis ligula, tincidunt malesuada tortor. Ut ac turpis erat. Mauris
78-
consequat, leo rhoncus venenatis elementum, sem nisl venenatis justo, non
79-
mattis diam massa vitae dolor. Aenean ac dolor et leo laoreet tincidunt.
80-
Suspendisse tempus risus nibh, a feugiat mauris pharetra a. Nulla mi dui,
81-
scelerisque vitae sollicitudin nec, placerat eget purus. Vivamus enim
82-
elit, scelerisque id venenatis eu, sodales vel leo. Quisque bibendum
83-
feugiat diam, ut feugiat urna suscipit et. Nulla lacinia metus a nisi
84-
volutpat interdum. Lorem ipsum dolor sit amet, consectetur adipiscing
85-
elit. Vestibulum vitae elit vel orci malesuada bibendum ut vitae enim. Ut
86-
ultrices elit nec vestibulum blandit. In eleifend dui. Nam nec aliquet
87-
nunc. Praesent convallis ipsum sed fermentum scelerisque.
88-
</p>
89-
<p>
90-
Praesent posuere, neque non fringilla ultricies, purus mi ullamcorper
91-
velit, vitae egestas nisl eros at ex. Nulla sed viverra libero. Praesent
92-
sed placerat magna, iaculis commodo lectus. Ut gravida ligula sed purus
93-
molestie, in accumsan est eleifend. Etiam consectetur nulla pretium
94-
blandit iaculis. Nunc semper libero ut mauris faucibus placerat. Cras ac
95-
justo ac est laoreet sollicitudin. Aliquam vel sapien ut sapien vestibulum
96-
dictum.
97-
</p>
131+
<p>Paragraph one.</p>
132+
<p>Paragraph two.</p>
98133
</section>
99134
<section class="left">
100135
<h2>Section in Landscape/Left</h2>
@@ -291,77 +326,16 @@ This example shows how the contents of a print document can be rotated to suit t
291326
</div>
292327
```
293328

294-
#### CSS
295-
296-
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.
297-
298-
```css
299-
@page upright {
300-
size: portrait;
301-
page-orientation: upright;
302-
}
303-
304-
@page left {
305-
size: landscape;
306-
page-orientation: rotate-left;
307-
}
308-
309-
@page right {
310-
size: landscape;
311-
page-orientation: rotate-right;
312-
}
313-
```
314-
315-
```css hidden
316-
fieldset {
317-
display: flex;
318-
flex-direction: row;
319-
justify-content: space-between;
320-
gap: 1rem;
321-
width: fit-content;
322-
}
323-
p {
324-
max-width: 60ch;
325-
}
326-
@media print {
327-
fieldset {
328-
display: none;
329-
}
330-
section {
331-
font-family: Roboto;
332-
font-size: 1.5rem;
333-
}
334-
}
335-
```
336-
337-
The following second part of the CSS code declares a named page rule defined above for the selectors, such as `<section class="left">…</section>`.
338-
339-
```css
340-
@media print {
341-
.upright {
342-
page: upright;
343-
}
344-
.left {
345-
page: left;
346-
}
347-
.right {
348-
page: right;
349-
}
350-
}
351-
```
352-
353-
```js hidden
329+
```js hidden live-sample___rotating-pages
354330
const printButton = document.querySelector("#print");
355331
printButton.addEventListener("click", () => {
356332
window.print();
357333
});
358334
```
359335

360-
### Result
361-
362-
Click the print button to see the pages rotated.
336+
Click the print button to see the page orientation on print.
363337

364-
{{ EmbedLiveSample('Rotating_printed_pages', '100%', 520) }}
338+
{{EmbedLiveSample('rotating-pages', '100%', '540', , , , , "allow-modals")}}
365339

366340
## Specifications
367341

files/en-us/web/css/_colon_first/index.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,36 @@ The **`:first`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/P
3030

3131
## Examples
3232

33-
### HTML
33+
### Using `:first` for page print styles
3434

35-
```html
35+
Press the "Print!" button to print the example. The words on the first page should be somewhere around the center, while other pages will have their contents at the default position:
36+
37+
```html live-sample___colon-first
3638
<p>First Page.</p>
3739
<p>Second Page.</p>
3840
<button>Print!</button>
3941
```
4042

41-
### CSS
42-
43-
```css
43+
```css live-sample___colon-first
4444
@page :first {
45-
margin-left: 50%;
46-
margin-top: 50%;
45+
size: 8.5in 11in;
46+
margin-left: 3in;
47+
margin-top: 5in;
4748
}
4849

4950
p {
5051
page-break-after: always;
52+
font: 1.2em sans-serif;
5153
}
5254
```
5355

54-
### JavaScript
55-
56-
```js
56+
```js live-sample___colon-first
5757
document.querySelector("button").addEventListener("click", () => {
5858
window.print();
5959
});
6060
```
6161

62-
### Result
63-
64-
Press the "Print!" button to print the example. The words on the first page should be somewhere around the center, while other pages will have their contents at the default position.
65-
66-
{{ EmbedLiveSample('Examples', '80%', '150px') }}
62+
{{EmbedLiveSample('colon-first', '100%', , , , , , "allow-modals")}}
6763

6864
## Specifications
6965

0 commit comments

Comments
 (0)