@page - CSS: Cascading Style Sheets 编辑

The @page CSS at-rule is used to modify some CSS properties when printing a document.

Syntax

@page {
  margin: 1cm;
}

@page :first {
  margin: 2cm;
}

Descriptors

size
Specifies the target size and orientation of the page box’s containing block. In the general case, where one page box is rendered onto one page sheet, it also indicates the size of the destination page sheet.
marks
Adds crop and/or registration marks to the document.
bleed
Specifies the extent beyond the page box at which the page rendering is clipped.

Description

You can't change all CSS properties with @page. You can only change the margins, orphans, widows, and page breaks of the document. Attempts to change any other CSS properties will be ignored.

The @page at-rule can be accessed via the CSS object model interface CSSPageRule.

Note: The W3C is discussing how to handle viewport-related <length> units, vh, vw, vmin, and vmax. Meanwhile do not use them within a @page at-rule.

Formal syntax

@page <page-selector-list> {
  <page-body>
}

where
<page-selector-list> = [ <page-selector># ]?
<page-body> = <declaration>? [ ; <page-body> ]? | <page-margin-box> <page-body>

where
<page-selector> = <pseudo-page>+ | <ident> <pseudo-page>*
<page-margin-box> = <page-margin-box-type> '{' <declaration-list> '}'

where
<pseudo-page> = : [ left | right | first | blank ]
<page-margin-box-type> = @top-left-corner | @top-left | @top-center | @top-right | @top-right-corner | @bottom-left-corner | @bottom-left | @bottom-center | @bottom-right | @bottom-right-corner | @left-top | @left-middle | @left-bottom | @right-top | @right-middle | @right-bottom

Examples

@page pseudo-class examples

Please refer to the various pseudo-classes of @page for examples.

  • :blank
  • :first
  • :left
  • :right
  • :recto This is an experimental API that should not be used in production code.
  • :verso This is an experimental API that should not be used in production code.

Specifications

SpecificationStatusComment
CSS Logical Properties and Values Level 1
The definition of ':recto and :verso' in that specification.
Editor's DraftAdds the :recto and :verso page selectors
CSS Paged Media Module Level 3
The definition of '@page' in that specification.
Working DraftNo change from CSS Level 2 (Revision 1), though more CSS at-rules can be used inside a @page.
CSS Level 2 (Revision 1)
The definition of '@page' in that specification.
RecommendationInitial definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:107 次

字数:11911

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文