JS text exceeds the length with ellipsis instead, hover and display the example with a floating box _javascript tips

Source: Internet
Author: User

The problem in question is split into two:

1. How do I use ellipsis instead of text when the length is exceeded?

2. How long is the length of the text after the omission of the display, how to hover when the mouse, in the form of a floating box to display all the information?

How do I implement ellipsis instead of text when it exceeds length?

Using CSS to implement a very long field with ellipses notation method: all browser compatible!

The HTML code is as follows:

<div style= "Width:150px;overflow:hidden; White-space:nowrap; Text-overflow:ellipsis ">
using CSS to implement a very long field is omitted simple method
</div>

Note: set width, Overflow:hidden, white-space:nowrap, text-overflow:ellipsis four attributes are indispensable. This type of writing can be displayed correctly in all browsers.

How to display all the information in the form of a hover box when the mouse hovers over a long length of text after omitting the display? (This only discusses how to display in a floating box)

The first way: Use the title attribute in the div:

Let's start with a simple, straightforward example:

<div style= ' width:120px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden ' title= ' mouse hover display content ' > Mouse hover content </div> 
<!--This content because it is inside Div, is control div width to show you need to see a few words of length, exceed will show ...-->
<!--title: hint Information, The cue information that the mouse puts on the element that is displayed-->

Display effects, as shown in the following figure:

The second way: Bind the mouse over the div in the event

Separate div (including id attribute) is displayed through the suspension box, and the following code is tested through Google Browser:

<! DOCTYPE html>
 
 

Multiple div (including class attribute) is displayed through a floating box:

Because the distance between the div tags, in the mouse suspension, the suspension box will appear fast flash, you can adjust the space between the Div, to improve, or directly to the P tag can also.

<! DOCTYPE html>  
 

The problems that exist:

When the mouse hovers over, omitted content in all show out, will squeeze the content below, when it is more than line display, easy to cause page confusion. Figure:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.