text-wrap-mode
text-wrap-mode CSS 屬性控制元素內部文字是否換行。不同的值提供了換行塊元素內容的替代方式。它也可以使用 text-wrap 簡寫屬性或 white-space 簡寫屬性進行設定和重置。
注意:white-space-collapse 和 text-wrap-mode 屬性可以使用 white-space 簡寫屬性一起宣告。
注意:此屬性的名稱是佔位符,有待 CSS 工作組找到更好的名稱。
試一試
text-wrap-mode: wrap;
text-wrap-mode: nowrap;
<section class="default-example" id="default-example">
<div class="whole-content-wrapper">
<p>Edit the text in the box:</p>
<div class="transition-all" id="example-element">
<p contenteditable="">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem aut
cum eum id quos est.
</p>
</div>
</div>
</section>
.whole-content-wrapper {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
#example-element {
border: 1px solid #c5c5c5;
width: 250px;
}
語法
css
/* Keyword values */
text-wrap-mode: wrap;
text-wrap-mode: nowrap;
/* Global values */
text-wrap-mode: inherit;
text-wrap-mode: initial;
text-wrap-mode: revert;
text-wrap-mode: revert-layer;
text-wrap-mode: unset;
值
此屬性指定是否可以在非強制軟換行處換行。可能的值:
正式定義
正式語法
text-wrap-mode =
wrap |
nowrap
示例
換行內容
預設設定是換行內容,因此不需要 text-wrap-mode 屬性。在此示例中,內容將流到下一行,以便它適合框中,最後一行比包含框長,因此溢位。
HTML
html
<div class="box">CSS IS AWESOME</div>
CSS
css
.box {
font-family: "Arial", sans-serif;
font-weight: bold;
font-size: 64px;
box-sizing: border-box;
border: 4px solid black;
padding: 0px 3px;
width: 223px;
text-wrap-mode: wrap;
}
結果
不換行內容
在此示例中,內容將不流到下一行,以便它適合框中,因為內容已被明確告知不要使用 text-wrap-mode: nowrap; 換行,內容比包含框長,因此溢位。
HTML
html
<div class="box">CSS IS AWESOME</div>
CSS
css
.box {
font-family: "Arial", sans-serif;
font-weight: bold;
font-size: 64px;
box-sizing: border-box;
border: 4px solid black;
padding: 0px 3px;
width: 223px;
text-wrap-mode: nowrap;
}
結果
規範
| 規範 |
|---|
| CSS 文字模組第 4 級 # text-wrap-mode |
瀏覽器相容性
載入中…