CSS @page 规则
定义和用法
CSS @page 规则用于自定义打印页面的尺寸、方向和边距。
实例
自定义打印页面:
@page :first {
margin-left: 40%;
margin-top: 50%;
}
@page :left {
margin-left: 10%;
margin-top: 10%;
}
@page :right {
margin-left: 90%;
margin-top: 90%;
}
CSS 语法
@page {
margin: value;
page-orientation: value;
size: value;
}
属性值
| 值 | 描述 |
|---|---|
| margin | 指定页面外边距。 |
| page-orientation | 指定页面的方向。 |
| size | 指定页面框包含块的目标尺寸和方向。 |
浏览器支持
表格中的数字表示首个完全支持该 @ 规则的浏览器版本。
| At-rule | Chrome | Edge | Firefox | Safari | Opera |
|---|---|---|---|---|---|
| @page | 2 | 12 | 19 | No | 6 |
| @page: size | 15 | 79 | 95 | No | 15 |
| @page: page-orientation | 85 | 85 | No | No | 71 |
| @page: @top-left | 131 | 不支持 | 不支持 | 不支持 | 不支持 |
| @page: @left-top | 131 | 不支持 | 不支持 | 不支持 | 不支持 |
| @page: @top-right | 131 | 不支持 | 不支持 | 不支持 | 不支持 |
| @page: @right-top | 131 | 不支持 | 不支持 | 不支持 | 不支持 |
| @page: @top-center | 131 | 不支持 | 不支持 | 不支持 | 不支持 |
| @page: @bottom-left | 131 | 不支持 | 不支持 | 不支持 | 不支持 |
| @page: @left-bottom | 131 | 不支持 | 不支持 | 不支持 | 不支持 |