- CSS 教程
- CSS - 首页
- CSS - 路线图
- CSS - 简介
- CSS - 语法
- CSS - 选择器
- CSS - 引入
- CSS - 测量单位
- CSS - 颜色
- CSS - 背景
- CSS - 字体
- CSS - 文本
- CSS - 图片
- CSS - 链接
- CSS - 表格
- CSS - 边框
- CSS - 块级边框
- CSS - 内联边框
- CSS - 外边距
- CSS - 列表
- CSS - 内边距
- CSS - 光标
- CSS - 轮廓
- CSS - 尺寸
- CSS - 滚动条
- CSS - 内联块
- CSS - 下拉菜单
- CSS - 可见性
- CSS - 溢出
- CSS - Clearfix
- CSS - 浮动
- CSS - 箭头
- CSS - 调整大小
- CSS - 引号
- CSS - 顺序
- CSS - 位置
- CSS - 连字符
- CSS - 悬停
- CSS - 显示
- CSS - 聚焦
- CSS - 缩放
- CSS - 转换
- CSS - 高度
- CSS - 连字符字符
- CSS - 宽度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 导航栏
- CSS - 覆盖层
- CSS - 表单
- CSS - 对齐
- CSS - 图标
- CSS - 图片库
- CSS - 注释
- CSS - 加载器
- CSS - 属性选择器
- CSS - 组合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 计数器
- CSS - 剪裁
- CSS - 书写模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - 隔离
- CSS - 滚动溢出
- CSS - Justify Items
- CSS - Justify Self
- CSS - 制表符大小
- CSS - 指针事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大块大小
- CSS - 最小块大小
- CSS - 混合模式
- CSS - 最大内联大小
- CSS - 最小内联大小
- CSS - 偏移量
- CSS - 口音颜色
- CSS - 用户选择
- CSS 高级
- CSS - 网格
- CSS - 网格布局
- CSS - Flexbox
- CSS - 可见性
- CSS - 定位
- CSS - 图层
- CSS - 伪类
- CSS - 伪元素
- CSS - @规则
- CSS - 文本效果
- CSS - 分页媒体
- CSS - 打印
- CSS - 布局
- CSS - 验证
- CSS - 图片精灵
- CSS - Important
- CSS - 数据类型
- CSS3 教程
- CSS3 - 教程
- CSS - 圆角
- CSS - 边框图片
- CSS - 多背景
- CSS - 颜色
- CSS - 渐变
- CSS - 盒阴影
- CSS - 盒装饰中断
- CSS - 光标颜色
- CSS - 文本阴影
- CSS - 文本
- CSS - 2d 转换
- CSS - 3d 转换
- CSS - 过渡
- CSS - 动画
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按钮
- CSS - 分页
- CSS - 变量
- CSS - 媒体查询
- CSS - 函数
- CSS - 数学函数
- CSS - 遮罩
- CSS - 形状
- CSS - 样式图片
- CSS - 特异性
- CSS - 自定义属性
- CSS 响应式
- CSS RWD - 简介
- CSS RWD - 视口
- CSS RWD - 网格视图
- CSS RWD - 媒体查询
- CSS RWD - 图片
- CSS RWD - 视频
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 转换器
- CSS - 颜色选择器和动画
- CSS 资源
- CSS - 有用资源
- CSS - 讨论
CSS 分页媒体 - break-before 属性
CSS break-before 分页媒体属性指定是否应该在元素之前发生分页符。这对于控制打印页面的布局很有用。
可能的值
以下是可以传递给b>break-before 分页媒体属性的一系列可能值
通用换行值
-
auto − 默认值。它将根据可用空间自动在元素之前换页。
-
avoid − 如果需要,它会避免在元素之前换页。
分页符值
-
avoid-page − 它会阻止在元素之前换页。
-
page − 强制在元素之前换页。
-
left − 强制在元素之前换页,以便下一页格式化为左侧页。
-
right − 强制在元素之前换页,以便下一页格式化为右侧页。
栏换行值
-
avoid-column − 避免在元素之前换栏。
-
column − 在元素之前添加栏换行。
应用于
块级元素。
DOM 语法
breakBefore = "auto|avoid|avoid-page|page|left|right|avoid-column|column";
分页符别名
Web 浏览器将旧版 page-break-before 属性视为 break-before 属性的别名。这确保了使用 page-break-before 的网站能够平稳运行。对于 break-before 属性,以下值应相等。
| page-break-before | break-before |
|---|---|
| auto | auto |
| left | left |
| right | right |
| avoid | avoid |
| always | page |
以下规则用于确定是否必须进行换行
任何三个相关值(always、left、right、page、column 或 region)中的 强制换行值 优先。如果存在多个分页符属性,我们选择序列中最后出现的那个。序列是 : break-before 优先于 break-after,而 break-after 优先于 break-inside。
如果任何三个相关值是 避免分页符值,例如 avoid、avoid-page、avoid-region 或 avoid-column,则在该位置不会添加分页符。
CSS break-before - auto 值
以下示例演示了(在打印布局中)break-before: auto 属性在打印页面时会自动在部分之前换页 -
<html>
<head>
<style>
main {
height: 50px;
width: 150px;
}
section {
break-before: auto;
border: 1px solid black;
padding: 5px;
margin: 10px;
}
button {
background-color: violet;
padding: 5px;
margin: 10px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<main>
<section>
<h3>Column 1</h3>
<p>This is a column 1.</p>
</section>
<section>
<h3>Column 2</h3>
<p>This is a column 2.</p>
</section>
<section>
<h3>Column 3</h3>
<p>This is a column 3.</p>
</section>
<section>
<h3>Column 4</h3>
<p>This is a column 4.</p>
</section>
<section>
<h3>Column 5</h3>
<p>This is a column 5.</p>
</section>
<section>
<h3>Column 6</h3>
<p>This is a column 6.</p>
</section>
<section>
<h3>Column 7</h3>
<p>This is a column 7. This section is break automatically based on the available space and content.</p>
</section>
</main>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS break-before - avoid 值
以下示例演示了(在打印布局中)break-before: avoid 属性在打印页面时会避免在部分之前换页 -
<html>
<head>
<style>
main {
height: 50px;
width: 180px;
}
section {
break-before: avoid;
border: 1px solid black;
padding: 5px;
margin: 10px;
}
button {
background-color: violet;
padding: 5px;
margin: 10px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<main>
<section>
<h3>Column 1</h3>
<p>This is a column 1.</p>
</section>
<section>
<h3>Column 2</h3>
<p>This is a column 2.</p>
</section>
<section>
<h3>Column 3</h3>
<p>This is a column 3.</p>
</section>
<section>
<h3>Column 4</h3>
<p>This is a column 4.</p>
</section>
<section>
<h3>Column 5</h3>
<p>This is a column 5.</p>
</section>
<section>
<h3>Column 6</h3>
<p>This is a column 6.</p>
</section>
<section>
<h3>Column 7</h3>
<p>This is a column 7.</p>
</section>
</main>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS break-before - avoid-page 值
以下示例演示了 break-before: avoid-page 属性在打印页面时会避免在元素之前换页 -
<html>
<head>
<style>
.avoid-break-page {
break-before: avoid-page;
}
button {
background-color: violet;
padding: 5px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<div><p>This is a paragraph 1. It will be displayed on first page.</p></div>
<div class="avoid-break-page"><p>This is a paragraph 2. It will be displayed on first page.</p></div>
<div><p>This is a paragraph 3. It will be displayed on first page.</p></div>
<div><p>This is a paragraph 4. It will be displayed on first page.</p></div>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS break-before - page 值
以下示例演示了 break-before: page 属性在打印页面时会换页 -
<html>
<head>
<style>
.break-page {
break-before: page;
}
button {
background-color: violet;
padding: 5px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<div><p>This is a paragraph 1. It will be displayed on first page.</p></div>
<div class="break-page"><p>This is a paragraph 2.After applying the break-before property, this paragraph will be displayed on the second page.</p></div>
<div><p>This is a paragraph 3. It will be displayed on second page.</p></div>
<div><p>This is a paragraph 4. It will be displayed on second page.</p></div>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS break-before - left 值
以下示例演示了 break-before: left 属性在打印页面时会将元素换到左侧的下一页 -
<html>
<head>
<style>
.page-break-left {
break-before: left;
}
button {
background-color: violet;
padding: 5px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<div><p>This is a paragraph 1. It will be displayed on first page.</p></div>
<div><p>This is a paragraph 2. It will be displayed on first page.</p></div>
<div class="page-break-left"><p>This is a paragraph 3.After applying the break-before: left property, this paragraph will be displayed to the next page on left side when page is printed.</p></div>
<div><p>This is a paragraph 4. It will be displayed on second page.</p></div>
<div><p>This is a paragraph 5. It will be displayed on second page.</p></div>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS break-before - right 值
以下示例演示了 break-before: right 属性在打印页面时会将元素换到右侧的下一页 -
<html>
<head>
<style>
.page-break-right {
break-before: right;
}
button {
background-color: violet;
padding: 5px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<div><p>This is a paragraph 1. It will be displayed on first page.</p></div>
<div><p>This is a paragraph 2. It will be displayed on first page.</p></div>
<div class="page-break-right"><p>This is a paragraph 3. After applying the break-before: right property, this paragraph will be displayed to the next page on right side when page is printed.</p></div>
<div><p>This is a paragraph 4. It will be displayed on second page.</p></div>
<div><p>This is a paragraph 5. It will be displayed on second page.</p></div>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS break-before - avoid-column 值
以下示例演示了 break-before: avoid-column 属性在打印页面时会避免在每个部分之前换栏 -
<html>
<head>
<style>
main {
column-width: 200px;
column-gap: 10px;
}
section {
width: 200px;
height: 130px;
border: 2px solid black;
margin: 10px;
padding: 5px;
}
.break-column {
break-before: avoid-column;
}
button {
background-color: violet;
padding: 5px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<main>
<section>
<h3>Column 1</h3>
<p>This is a column 1.</p>
</section>
<section class="break-column">
<h3>Column 2</h3>
<p>This is a column 2.</p>
</section>
<section>
<h3>Column 3</h3>
<p>This is a column 3.</p>
</section>
<section>
<h3>Column 4</h3>
<p>This is a column 4.</p>
</section>
</main>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>
CSS Break column - column 值
以下示例演示了 break-before: column 属性在打印页面时会在每个部分之前添加栏换行以创建多栏布局 -
<html>
<head>
<style>
main {
column-width: 200px;
column-gap: 10px;
}
section {
width: 200px;
height: 130px;
border: 2px solid black;
margin: 10px;
padding: 5px;
}
.break-column {
break-before: column;
}
button {
background-color: violet;
padding: 5px;
}
</style>
</head>
<body>
<p>Click on below button to see the effect when you print the page.</p>
<button onclick="printPage()">Print Page</button>
<main>
<section>
<h3>Column 1</h3>
<p>This is a column 1.</p>
</section>
<section class="break-column">
<h3>Column 2</h3>
<p>This is a column 2. After applying break-before: column, this section will be displayed on next column.</p>
</section>
<section>
<h3>Column 3</h3>
<p>This is a column 3.</p>
</section>
<section>
<h3>Column 4</h3>
<p>This is a column 4.</p>
</section>
</main>
<script>
function printPage() {
window.print();
}
</script>
</body>
</html>