Using Ellipsis to truncate long text lines in CSS

栏目: IT技术 · 发布时间: 6年前

内容简介:I useThis can be done quite easily in CSS thanks to the declaration

I use grammarly.com to correct the articles from this blog given that English's not my primary language. In this app, if you set a longer title a document you will get the ellipsis sign after a specific length.

Using Ellipsis to truncate long text lines in CSS

This can be done quite easily in CSS thanks to the declaration text-overflow: ellipsis; .

Hoever keep in mind that for this to work you will also need to:

  • set a clear width to the text so that there is a limit for how much the text can expand
  • and also a nowrap alongside overflow: hidden so that the text will stay on one line and will not go outside the container

The full declaration for a truncation class may look like this:

.truncate-to-300 { 
    text-overflow: ellipsis; 
    width: 300px;
    white-space: nowrap; 
    overflow: hidden; 
}

And to get the output from the picture we can just to:

<h1>A CSS tricky situation- the order of the CSS class names in the HTML tags</h1>

There are also techniques that allow to truncate the text after multiple lines but there are a bit more troublesome to implement.

I hope you have enjoyed this article and if you would like to get more articles about React and frontend development you can always sign up for my email list.


以上所述就是小编给大家介绍的《Using Ellipsis to truncate long text lines in CSS》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

PHP5与MySQL5 Web开发技术详解

PHP5与MySQL5 Web开发技术详解

杜江 / 电子工业出版社 / 2007-11 / 79.00元

《PHP5与MySQL5 Web开发技术详解》(含光盘)是目前中文版本第一个真正介绍PHP5及MYSQL5新增语法与功能的权威宝典!一起来看看 《PHP5与MySQL5 Web开发技术详解》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具