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

2019-01-12 15:11发布

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.

标签: css text wrap
4条回答
Evening l夕情丶
2楼-- · 2019-01-12 15:33

You can use CSS white-space Property to achieve this.

white-space: nowrap
查看更多
劫难
3楼-- · 2019-01-12 15:39

Sometimes using   instead of spaces will work. Clearly it has drawbacks, though.

查看更多
Root(大扎)
4楼-- · 2019-01-12 15:46

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

Note: this only works on block elements. If you need to do this to table cells (for example) you need to put a div inside the table cell as table cells have display table-cell not block.

As of CSS3, this is supported for table cells as well.

查看更多
Bombasti
5楼-- · 2019-01-12 15:49

Using ellipsis will add the ... at the last.

   <style type="text/css">
    div {
      white-space: nowrap;
      overflow: hidden;
text-overflow: ellipsis;
    }
    </style>
查看更多
登录 后发表回答