@page
@page 规则用于在打印文档时修改某些CSS属性。你不能用@page规则来修改所有的CSS属性,而是只能修改margin,orphans,widow 和 page breaks of the document。对其他属性的修改是无效的。
@page {
margin: 1cm;
}
@page :first {
margin: 2cm;
}
@page
规则可以通过 CSS 对象模型接口的 CSSPageRule
访问。
语法
描述符
形式化语法
@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> (en-US) <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
示例
规范
规范 | 状态 | 备注 |
---|---|---|
CSS Logical Properties and Values Level 1 :recto and :verso |
Editor's Draft | Adds the :recto and :verso page selectors |
CSS Paged Media Module Level 3 @page |
Working Draft | No change from CSS Level 2 (Revision 1), though more CSS at-rules can be used inside a @page . |
CSS Level 2 (Revision 1) @page |
Recommendation | Initial definition |
浏览器兼容性
BCD tables only load in the browser
参见
- See the [META] CSS Paged Media Module Level 3 ticket in Bugzilla for tracking progress on the subject (page-based counters, etc.)