CSS溢出-仅1行文字 [英] css overflow - only 1 line of text

查看:64
本文介绍了CSS溢出-仅1行文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的div具有以下CSS样式:

I have div with the following css style:

width:335px; float:left; overflow:hidden; padding-left:5px;

当我在div中插入一长行文本时,它会换行并显示所有文本.我想要的是只有一行不会换行的文本.当文本较长时,我希望此溢出文本消失.

When I insert, into that div, a long line of text, it's breaking to a new line and displays all the text. What I want is to have only one line of text that will not line-break. When the text is long, I want this overflowing text to disappear.

我当时正在考虑设置高度,但这似乎是错误的.

I was thinking about setting the height but it seems to be wrong.

也许我添加与字体相同的高度,它应该可以工作并且不会在不同的浏览器中引起任何问题吗?

Maybe if I add height that is the same as the font, it should work and not cause any problems in different browsers?

我该怎么办?

推荐答案

如果要将其限制为一行,请在div上使用white-space: nowrap;.

If you want to restrict it to one line, use white-space: nowrap; on the div.

这篇关于CSS溢出-仅1行文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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