Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
举个简单的例子,这个:文本应该在一行,但由于 div 太小,它被分成三行。如何让文本在不换行的情况下从 div 中溢出?
html:
<div style="width: 20px;">Some text here</div>
结果:
Some text here
我要这个:
尝试这个:
<div style="width: 20px; white-space: nowrap;">Some text here</div>
当 div 具有属性white-space: no-wrap时,其子元素继承相同的属性。如果您想包装子元素,可以使用white-space: normal;
white-space: no-wrap
white-space: normal;
jsFiddle
当然这是可行的,但是如果使用的 div 的数量超过了使用normal的 div 的数量nowrap,我建议nowrap通过将文本放在自己的 div 中来隔离文本。
normal
nowrap