Use CSS to process long strings

Source: Internet
Author: User
Line feed display of long strings

For Chinese characters, long strings are not a problem. The browser can use a correct line feed, but for English characters, it may break through the width of the container and affect the appearance. The solution is not difficult, but the compatibility between IE and Firefox must be considered:

<Div style = "width: 100px; Height: 100px; Border: 1px solid #000000; Word-wrap: Break-word; overflow: hidden;">
Abcdefghijklmnopqrstuvwxyz
</Div>

IE will set the correct line feed according to the word-wrap settings. Although Firefox does not recognize word-wrap, it will make a proper deal according to the overflow settings.

Pay attention to using IE as much as possibleWord-wrapInsteadWord-breakThis is because word-break does not process consecutive punctuation marks.

Long String omitted display

Sometimes, when processing long strings, you must keep a single line. In this case, you can only hide the excess parts and add the ellipsis at the end:

<Div style = "width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
One world. One dream.
</Div>

In IE, everything works normally, but in Firefox, the text-overflow attribute is not supported, and only redundant parts of the string can be simply hidden.

Firefox does not support word-wrap: Break-word or text-overflow: ellipsis. For simple solutions, overflow: Den den is used to hide them. For complex solutions, there are many methods of the hack class.

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.