:first
:first
CSS 伪类与 @page
at 规则一起使用。表示打印文档的第一页。(有关节点的第一个元素,请参阅 :first-child
。)
css
/* 打印时选择第一页 */
@page :first {
margin-left: 50%;
margin-top: 50%;
}
语法
css
:first {
/* ... */
}
示例
HTML
html
<p>第一页。</p>
<p>第二页。</p>
<button>打印!</button>
CSS
css
@page :first {
margin-left: 50%;
margin-top: 50%;
}
p {
page-break-after: always;
}
JavaScript
js
document.querySelector("button").addEventListener("click", () => {
window.print();
});
结果
按下“打印!”按钮以打印此示例。第一页的文字应该大致位于中心位置,而其他页的内容将位于默认位置。
规范
Specification |
---|
CSS Paged Media Module Level 3 # left-right-first |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
First page pseudo-class ( :first ) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.