The content of the CSS control exceeds the container width and the ellipsis is displayed

Source: Internet
Author: User
css| Control | show

Generally we see such as news list, in order to make the text does not return to the line, control the number of words, through the program so that superfluous characters show ellipsis, we only use CSS can achieve the same effect, although not perfect.

Li {
width:50px;
White-space:nowrap;
Text-overflow:ellipsis;
Overflow:hidden;
}

First is a container, can be div,li,td, and so on, first define the width, "white-space:nowrap" is forced to display all the text in a row, not back. "Text-overflow:ellipsis" is the key.

Text-overflow is the CSS3 new attribute, supported by IE6 above version. It can take 2 parameters: Clip [does not show ellipsis (...). , but a simple trim],ellipsis[display an ellipsis (...) when text overflows inside an object. )]。 So, this method does not support Firefox. Therefore, we also need to add a overflow:hidden, so that the extra text in FF hidden.

Although hit the effect, but because the effect is also very convenient with program control, and there is no browser compatibility problem, so the method of using the CSS to appear chicken.



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.