CSS:将元素限制为1行 [英] CSS: limit element to 1 line

查看:538
本文介绍了CSS:将元素限制为1行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个元素限制为只显示一行文字,其余部分隐藏(overflow:hidden),而不设置特定高度。这是可能的只是CSS?

I want to limit a element to display only 1 line of text, with the remainder hidden (overflow:hidden), without setting a specific height. Is this possible with just CSS?

推荐答案

可能:

element (white-space: nowrap; overflow: scroll;)

文本解析为HTML或XML是标记化的,这意味着所有空白运行都被折叠到一个空格字符。这意味着你将有一行文本,除非你指定的溢出声明之外,可能导致你的文本换行。

Text parsed as HTML or XML is tokenized, which means all runs of whitespace are collapsed to a single space character. This means you will have a single line of text unless you specify something in addition to the overflow declaration that could cause your text to wrap.

编辑:我没有包括必要的写入空间:nowrap属性,否则默认是一个容器将水平地垂直滚动。

I failed to include the necessary write-space: nowrap property, otherwise the default is that a container will scroll vertically opposed to horizontally.

这篇关于CSS:将元素限制为1行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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