- 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>