
- 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 - isolation
- CSS - overscroll
- CSS - justify-items
- CSS - justify-self
- CSS - tab-size
- CSS - pointer-events
- CSS - place-content
- CSS - place-items
- CSS - place-self
- CSS - max-block-size
- CSS - min-block-size
- CSS - mix-blend-mode
- CSS - max-inline-size
- CSS - min-inline-size
- CSS - offset
- CSS - accent-color
- CSS - user-select
- 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 - box-decoration-break
- CSS - caret-color
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - box-sizing
- 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 - widows 屬性
在 CSS 中,`widows` 屬性用於控制在頁面、區域或列中斷之前必須在頁面或列頂部顯示的文字塊的最小行數。與 `orphans` 屬性一樣,它通常用於管理分頁並確保顯示特定數量的行以提高列印文件或多列布局的可讀性。
如果塊頂部的行數少於 `widows` 屬性的值,則該塊將移動到下一頁或下一列,以確保顯示指定數量的行。
根據排版,`widows` 是段落的最後一行,單獨出現在頁面的頂部;當段落從舊頁面繼續時。
可能的值
**<integer>**: 指定在分塊中斷後可以在片段頂部顯示的行數。它應該只有正值。預設值為 2。
應用於
所有塊級元素。
DOM 語法
object.style.widows = "3"
與orphans 屬性(控制在塊底部顯示的最小行數)一起,`widows` 屬性有助於控制內容在頁面或列中的流動和中斷方式,確保特定數量的內容保持在一起,從而提高列印文件或多列布局的可讀性和美觀性。
`widows` 屬性在 Firefox 瀏覽器上不受支援。
CSS widows - <integer> 值
以下示例顯示了 `widows` CSS 屬性的用法,其中 `widows` 值透過類宣告(.widows-demo)作為 <integer> 傳遞。
<html> <head> <style> div.widows-demo { background-color: tomato; height: 170px; columns: 3; widows: 3; padding: 5px; } p { background-color: lightyellow; } p:first-child { margin-top: 0; } </style> </head> <body> <h1>Widows property</h1> <div class="widows-demo"> <p>Paragraph one that shows some text having just one line.</p> <p> Paragraph two in the same div "widows-demo", with some styling applied. Testing for the working of orphan property of CSS. There are three lines in this paragraph. Paragraph two having few more lines for some extra content for the testing purpose. </p> <p> Paragraph three for some extra text for the testing purpose. Second line in the third paragraph to test the widows property. </p> </div> </body> </html>
在上面的例子中
在 div 元素上定義了一個類 (widows-demo),具有 CSS 樣式,例如 background-color、height、padding、column 和 widows。
該 div 分為三列,widows 值設定為 3。
在父 div 下添加了三個 p 元素。
輸出基於 widows 屬性的值(在本例中為 3),並且隨著片段中斷,內容將相應顯示。
**注意:**更改螢幕尺寸以檢視佈局的變化。
CSS widows - initial 值
以下示例顯示了 `widows` CSS 屬性的用法,其中 `widows` 值透過 id 宣告設定為 `initial`,稍後在 div 元素上呼叫。
<html> <head> <style> #widows-demo { columns: 3; column-gap: 5em; widows: initial; } div { background-color: green; padding: 5px; } p { background-color: antiquewhite; } span { font-style: italic; color: red; font-weight: bold; } </style> </head> <body> <div id="widows-demo"> <p> <span> Paragraph one in the div, with some styling applied. Testing for the working of widows property of CSS. There are three lines in this paragraph. Paragraph one having few more lines for some extra content for the testing purpose. The widows CSS property is used to set the minimum number of lines on the new page. Paragraph one in the div, with some styling applied. Testing for the working of widows property of CSS. There are three lines in this paragraph. Paragraph one in the div, with some styling applied. Testing for the working of widows property of CSS. There are three lines in this paragraph. </span> </p> <p> Paragraph two in the same div, with some styling applied. Testing for the working of widows property of CSS. There are three lines in this paragraph. Paragraph two having few more lines for some extra content for the testing purpose. The widows CSS property is used to set the minimum number of lines on the new page. </p> <p> Paragraph three for some extra text for the testing purpose. Second line in the third paragraph. Testing for the widows property which takes up an integer value or initial / inherit values. </p> <p> Paragraph four in the third column of the page. Number of lines in this paragaraph is two. Testing for the orphans CSS property which takes up an integer value or initial / inherit values. </p> </div> </body> </html>
定義了一個 id (#widows-demo) 並將其應用於 div 元素,具有 CSS 樣式,例如 column、column-gap 和 widows。
該 div 分為三列,間隙為 5em,widows 值設定為 initial,預設為 2。
在父 div 下添加了四個 p 元素。
輸出基於 widows 屬性的值(在本例中為 inherit),並且隨著片段中斷,內容將相應顯示。
CSS widows - 媒體列印
以下示例顯示了 `widows` CSS 屬性的用法,其中 `widows` 值透過媒體查詢 (@media print) 設定為 <integer>。
<html> <head> <style> @media print { p { widows: 5; columns: 3; column-gap: 3em; } button { display: none; } } </style> </head> <body> <article> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> <p> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consequatur facilis vitae voluptatibus odio consequuntur optio placeat? Id, nam sequi aut in dolorem dolores, laudantium, quasi totam ipsam aliquam quibusdam velit. </p> </article> <button>Print</button> <script> const button = document.querySelector("button"); button.addEventListener("click", () => { window.print(); }); </script> </body> </html>
定義了一個媒體查詢並將其應用於 p 元素,在列印模式下,具有 CSS 樣式,例如 column、column-gap 和 widows。
有一個“列印”按鈕,單擊該按鈕會在內容上應用 widows 值,即 5。
新部分顯示最後一段的最後五行,位於頂部。