text-wrap 属性用于控制文本的换行方式。
值
normal:默认值,文本将根据容器的宽度自动换行。none:禁止文本换行。unrestricted:文本可以在任意字符之间换行,不会考虑单词边界。suppress:文本可以在任意字符之间换行,但会考虑单词边界。
示例代码
// www.javascriptcn.com code example
.text {
text-wrap: normal;
}
.text-no-wrap {
text-wrap: none;
}
.text-unrestricted {
text-wrap: unrestricted;
}
.text-suppress {
text-wrap: suppress;
}在上面的示例代码中,.text 类应用了 text-wrap: normal; 属性,将文本根据容器的宽度自动换行。.text-no-wrap 类应用了 text-wrap: none; 属性,禁止文本换行。.text-unrestricted 类应用了 text-wrap: unrestricted; 属性,允许文本在任意字符之间换行,不考虑单词边界。最后,.text-suppress 类应用了 text-wrap: suppress; 属性,允许文本在任意字符之间换行,但会考虑单词边界。
以上就是关于 CSS 属性 text-wrap 的介绍,希望能帮助你更好地掌握这个属性的用法。