Home>Article>Web Front-end> How to set text in html without wrapping

How to set text in html without wrapping

coldplay.xixi
coldplay.xixi Original
2021-04-27 16:00:40 13708browse

html Methods to set text without line breaks: 1. General text truncation, the code is [word-break:keep-all;white-space:nowrap;]; 2. Hide the excess content, the code is [overflow:hidden;].

How to set text in html without wrapping

The operating environment of this tutorial: windows7 system, html5 version, DELL G3 computer.

html Method to set text without line wrapping:

General text truncation (applicable to inline and block):

.text-oneLine{ display:block; /*内联对象需加*/ word-break:keep-all; /* 不换行 */ white-space:nowrap; /* 不换行 */ overflow:hidden; /* 内容超出宽度时隐藏超出部分的内容 */ text-overflow:ellipsis; /* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/ }

For tables, define Different:

table{ width:30px; table-layout:fixed; /* 只有定义了表格的布局算法为fixed,下面td的定义才能起作用。 */ } td{ width:100%; word-break:keep-all; /* 不换行 */ white-space:nowrap; /* 不换行 */ overflow:hidden; /* 内容超出宽度时隐藏超出部分的内容 */ text-overflow:ellipsis; /* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/ }

Related learning recommendations:html video tutorial

The above is the detailed content of How to set text in html without wrapping. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn