CSS uses overflow to hide out-of-range content (text is too long hidden)

Source: Internet
Author: User

<style type= "Text/css" >
. textoverflow {
width:300px;
Overflow:hidden;
Text-overflow:ellipsis;
White-space:nowrap;
border:1px solid #ddd;
}
</style>
<div class= "Textoverflow" >
Various types of source code, CSS effect codes and common software download. </div>
</div>
</div>
</body>

Because of the need for Web publishing, some places require too long questions plus ellipses. For example: the title limit of 20 Chinese width, beyond the use of ellipses instead. The method used to intercept the program before, but using CSS to intercept more conducive to SEO.

Here's a look at how to use this:

<div class= "title" > Display ellipsis when text overflows in objects </div>

This is an example, in fact we only need to display the following length:

CSS implementation of the page text too long interception ...

The title class should write this:

. title{width:300px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}

Description

1, the width must be set, can be adjusted according to the actual needs.

2, White-space:nowrap is prohibited text folding line.

3. Text-overflow Indicates whether an ellipsis is displayed when text overflows, with two values:

Clip: Do not display the ellipsis tag (...). ), but a simple cut.
Ellipsis: Displays ellipsis (...) when text inside an object overflows. )

4, Overflow:hidden indicates that overflow content is hidden.

Example:

#FormatImgID_0 #

Example code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>text-overflow</title>
<body>
<style type= "Text/css" >
Test_demo_clip{text-overflow:clip; overflow:hidden; white-space:nowrap; width:200px; background: #ccc;}
test_demo_ellipsis{text-overflow:ellipsis; overflow:hidden; white-space:nowrap; width:200px; background: #ccc;}
</style>
<div class= "Test_demo_clip" >
Does not display ellipsis, but a simple trimming bar
</div>
<div class= "Test_demo_ellipsis" >
Show ellipsis when text inside an object overflows
</div>
</body>

CSS uses overflow to hide out-of-range content (text is too long 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.