Use CSS to skillfully display ultra-long text content

Source: Internet
Author: User

In reality, some texts with relatively long content often appear. In order to make the overall layout look good, you need to control the text content in one line for display and take a certain length, and place the content in place of ellipsis. Although it can be controlled by dynamic languages, this is not conducive to search engine indexing. CSS can be used to solve this problem skillfully. See the following code: Code 1: it can be used for non-Table LI or span. text-overflow {display: block;/* inline objects need to be added */width: 31em; word-break: keep-all;/* Do not wrap */white-space: nowrap; /* Do not wrap */overflow: hidden;/* Hide content beyond the width of the content */text-overflow: ellipsis; /* when the object text overflows, the omitted mark (...) is displayed (...); must be used with overflow: hidden. */} Code 2: used for table {width: 30em; table-layout: fixed;/* the following definition of td takes effect only when the table layout algorithm is defined as fixed. */} Td {width: 100%; word-break: keep-all;/* Do not wrap */white-space: nowrap;/* Do not wrap */overflow: hidden; /* Hide the content in excess of the content when the content exceeds the width */text-overflow: ellipsis;/* display the omitted mark (...) when the text in the object overflows (...); must be used with overflow: hidden. */}

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.