The text overflow of the webpage displays the ellipsis

Source: Internet
Author: User

1, single-line text overflow display ellipsis CSS notation

1 Overflow:hidden; 2 text-overflow:ellipsis; 3 White-space:nowrap; /* No Line break */

2, multiple lines of text display ellipsis

This is achieved based on the application scenario.

1) WebKit Browser or mobile page

You can use the private property of WebKit:-webkit-line-clamp (This property is not part of the CSS specification), which is used to display the number of lines of text displayed by the block element. To achieve this effect, you need to combine additional webkit properties.

Common combinations of properties:

    • display: -webkit-box;You must combine the properties to display the object as an elastic telescopic box model.
    • -webkit-box-orientYou must combine properties to set or retrieve the arrangement of child elements of a telescopic box object.
    • text-overflow: ellipsis;, you can use the ellipsis "..." to hide out-of-range text in the case of multiple lines of text

For example:

1<!DOCTYPE HTML>2<HTML>3<HeadLang= "en">4<MetaCharSet= "UTF-8">5<title>Multi-line text overflow ellipsis</title>6<style>7. Text-contorl{8 Display:-webkit-box;9-webkit-box-orient:Vertical;10-webkit-line-clamp:3;/*display 3 lines of text*/Text-overflow:ellipsis;font-size:16px;Border:1px solid #ccc;width:500px;Max-height:300px;Overflow:Hidden; -} -</style> +</Head> -<Body> +<Pclass= "Text-contorl">22 Summary: Before the company was made with Flash this site, now because of slow access or other reasons, I have to use HTML5 re-write, layout and the previous is the same. The overall need to achieve the following features: (1) Background image Carousel (2) Text animation (3) navigation bar animation effect (4) Design picture display effect (do not know how to write, in fact, I did not understand its implementation principle, almost is the picture of seamless</P> -</Body> -</HTML>

Run effect

2) cross-browser compatibility scenarios

The more reliable way is to set the relative positioning of the container height, with an ellipsis (... ) The implementation of elemental simulation

For example:

<!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <title>Multi-line text overflow ellipsis</title>    <style>. Text-contorl{position:relative;Line-height:1.4em;Height:3.2em;Overflow:Hidden;        }. Text-contorl:after{content: "...";Font-weight:Bold;Bottom:0; Right:0;padding:0;                   }    </style></Head><Body><Pclass= "Text-contorl">Abstract: Before the company is to do this site with Flash, now because of slow access or other reasons, I have to use HTML5 re-write 4) design pictures of the display effect (do not know how to write, in fact, I have not figured out the principle of its implementation, almost the picture of seamless scrolling. </P></Body></HTML>

Run effect

It is important to note that:

    • Height needs to be set exactly 3 times times line-height (the test found that if the height value is set too small and the ellipsis is not displayed, you may need to adjust it as needed)
    • The end of the omitted to use the translucent PNG to do a dodge effect, or set the background color;
    • Ie6-7 does not display content content, so to be compatible with IE6-7 can be to add a tag to the content, for example, <span class="line-clamp">...</span> to simulate;
    • To support IE8, it needs to be ::after replaced :after ;

Reference from: http://www.css88.com/archives/5206

The text overflow of the webpage displays the ellipsis

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.