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 |
浏览器兼容性
加载中…