If the implementation of a single line of text overflow display ellipsis students should know to use the Text-overflow:ellipsis attribute, of course, also need to add width of the genus to be compatible with some of the browsing.
Implementation method:
Overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
Effect
But this property only supports a single line of text overflow display ellipsis, if we want to implement multi-line text overflow display ellipsis it.
The next step is to say that multiple lines of text overflow display ellipses, as follows.
Implementation method:
Display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden;
Effect
Scope of application:
Due to the use of WebKit CSS extension properties, this method is suitable for WebKit browser and mobile side;
Note:
1.-webkit-line-clamp is used to limit the number of lines of text displayed in a block element. To achieve this effect, it needs to combine other WebKit properties. Common binding Properties:
2.display:-webkit-box; You must combine the properties to display the object as an elastic telescopic box model.
3.-webkit-box-orient must combine properties to set or retrieve the arrangement of child elements of a telescopic box object.
Implementation method:
p{position:relative; line-height:20px; max-height:40px;overflow:hidden;} P::after{content: "..."; Position:absolute; bottom:0; Right:0;padding-left:40px;background:-webkit-linear-gradient (left, Transparent, #fff 55%); background:- O-linear-gradient (right, transparent, #fff 55%); background:-moz-linear-gradient (right, transparent, #fff 55%); Background:linear-gradient (to right, transparent, #fff 55%);}
Effect
Scope of application:
This method can be used in a wide range of applications, but the text does not exceed the line of the case will also appear ellipsis, combined with JS optimization of the method.
Note:
1. Set height to an integer multiple of line-height to prevent excess text from revealing.
2. Add a gradient background to P::after to prevent text from appearing in half.
3. Because ie6-7 does not display content contents, it is necessary to add a label compatible with ie6-7 (such as:<span>...<span/>); compatible IE8 need to replace: After replaced by: after.
"Recommended"
1. HTML text control display the number of words beyond the use of ellipsis method
2. Use CSS to resolve the title display the number of words out of the way
3. Online CSS free video tutorial