如何阻止文本占用多于1行? [英] How to stop text from taking up more than 1 line?

查看:76
本文介绍了如何阻止文本占用多于1行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在自动换行或其他任何阻止文字换行的属性?我的身高是overflow:hidden,但文本仍然中断.

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.

需要在CSS3之前的所有浏览器中工作.

Needs to work in all browsers, before CSS3.

推荐答案

div {
  white-space: nowrap;
  overflow: hidden;
}

<div>test that doesn't wrap</div>

注意:这仅适用于块元素.例如,如果您需要对表格单元格执行此操作,则需要在表格单元格内放置一个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.

从CSS3开始,表格单元格也支持此功能.

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

这篇关于如何阻止文本占用多于1行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆