The text in the div displays two lines, and the extra text is displayed with an ellipsis

Source: Internet
Author: User

With the-webkit-private attribute, the code is as follows:

There are other ways to solve this problem:
1, through JS to control the word count, and then intercept the text
Here is an example:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> examples </title>
<style type= "Text/css" >
. demo{width:100px;}
<div class= "Demo" id= "Demo" > How to display two lines or three lines of text, then the extra part of the ellipsis instead of?</div>
JS can not directly through the class to get objects, you must write a method, so that the efficiency is very low, the original JS best with the ID to get the Domo object directly with the ID

var Obox=document.getelementbyid (' demo ');
The slice () method returns the selected element from an existing array.
You can use negative values to select elements from the end of an array.
If end is not specified, then the slice () method selects all elements from start to the end of the array.
Here, you need to modify the value of slice () to achieve what you want to display.
var demohtml = OBox.innerHTML.slice (0,10) + ' ... ';
Fill to specified position
obox.innerhtml = demohtml;

2, there is a method is through the background control, with program control, the output of the process is controlled; this will not ...

The text in the div displays two lines, and the extra text is displayed with an 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: 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.