CSS implementation single-line and multiline text ellipsis (truncation)

Source: Internet
Author: User
This article makes a simple record of the implementation of this effect (including single-line text overflow ellipsis) in case you forget. Specifically, it is to achieve this text arrangement effect.

The HTML code is as follows:

<div class= "Container" >  <div class= "box" >    <div class= "box-content" >      

The common CSS styles are as follows:

. container {  margin:50px auto;  width:328px;}. box {  background: #f7f7f7;}. box-content {  padding:20px;}. Box-content-title {  margin:0 0 20px;}. Box-content-desc {  color: #333;  font-size:14px;  line-height:1.5;  margin-bottom:10px;  Overflow:hidden;}. Box-content-link {  color: #006ec8;  font-size:14px;  Text-decoration:none;}

Note the above Overflow:hidden; To be preserved.

Single-line text overflow omitted:

1singleline{

2 text-overflow:ellipsis;

3 white-space:nowrap;

4}

The Text-overflow property specifies how to display the overflow text content, its property value can be elipsis (...), clip (truncate), custom string, I tried in chrome, I found the custom string is not good.

Again see multiline text overflow omitted:

. Multiline {  display:-webkit-box;  text-overflow:ellipsis;;  -webkit-box-orient:vertical;  -webkit-line-clamp:4;}

You can see the use of the nonstandard CSS notation, that is, the wording with the WebKit prefix (webkit kernel browser private property), there is a number of outdated wording,

Display:-webkit-box;
-webkit-box-orient:vertical;
-webkit-line-clamp:4;

There is not much to explain (in fact, the explanation does not understand), multi-line ellipsis method is not very good. Let's look at other better ways later.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.