CSS: how to stop text from taking up more than 1 line?

Is there a word-wrap or any other attribute that stops text from wrapping? I have a height, and overflow:hidden , and the text still breaks.

Needs to work in all browsers, before CSS3.


div {
  white-space: nowrap;
  overflow: hidden;
}
<div>test that doesn't wrap</div>

您可以使用CSS white-space Property来实现此目的。

white-space: nowrap

使用省略号将在最后添加...。

   <style type="text/css">
    div {
      white-space: nowrap;
      overflow: hidden;
text-overflow: ellipsis;
    }
    </style>
链接地址: http://www.djcxy.com/p/81356.html

上一篇: 块元素包装在文本内容上

下一篇: CSS:如何阻止文本占用超过1行?