Solving the problem of intercepting ellipsis of mixed strings in Chinese and English by using CSS-Experience exchange

Source: Internet
Author: User
Tags mixed
As a programmer, often need to face a problem is in the news, such as information in the title list, often in order to adapt to the width of the table, the need for the long title of the text to intercept and at the end of the truncated text with ellipses.

As we all know, there are many ways to achieve this function, javascript,asp,php have their own implementation methods, but there are many problems, such as mixed in English or in some coding, easy to cause the interception of garbled problems, although most of the problems have been more mature solutions, However, when the amount of data is large, the use of javascript,asp,php to achieve this function, will undoubtedly give the client or server side caused a relatively large resource costs.

With the popularity of the popular, many sites are in the traditional form into the layout of the div+css, I studied the CSS and div Some features, found a more interesting CSS, after a series of research and experiments, found a use of div+ CSS to implement this function of the alternative method, this method in my test can be no problem, and good compatibility with a variety of coding and Chinese and English mixed-row situation.

Methods in Div:

< DIV style="width:200px; border:1px dashed red; Overflow:hidden; Text-overflow:ellipsis ">
<nobr> is like a line of text, very long, a row in the table does not show .</nobr>
<nobr> A is for example a line of text, very long, a row in the table does not appear .</nobr>
<nobr> 1 is like a line of text, very long, a row in the table does not appear .</nobr>
<nobr> F is for example a line of text, very long, a row in the table does not appear .</nobr>
<nobr> is like you Pig Very Very Very much.<
</div>

Methods in table:

< table  style= table-layout:fixed;border-collapse: collapse;font-size:12px; "  border= "1"  width= ""  bordercolor= #666666 >
tr>
td nowrap  style= "overflow:hidden;text-overflow:ellipsis;" > Content Content Contents content content content content content content content content content contents content; / td>
/
Tr> / table> The the


Code is simple and should basically be easy to see , mainly in the "Text-overflow" attribute, this property has 2 values, respectively, "ellipsis" and "clip", simple understanding, the first value will be intercepted at the end of the text with the ellipsis, the second value will not.

This method at present I have not found any bug,css control, nor does it cause too much overhead, self feeling, is a useful method!

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.