1.单行文本溢出
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title> < style> * { margin : 0; padding : 0; box-sizing : border-box; } .container { width : 300px; margin : 50px auto; padding : 0 10px; text-align : justify; line-height : 30px; border : 1px solid #000; white-space : nowrap; overflow : hidden; text-overflow : ellipsis; } </ style>
</ head> < body> < div class = " container" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique, doloribus? Ratione laboreiure, minima voluptatem dolore possimus soluta ea minus tempore animi officia accusantium nulla, maiores,delectus vero debitis recusandae.</ div>
</ body> </ html>
2.多行文本溢出处理
2-1.方法一:
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title> < style> * { margin : 0; padding : 0; box-sizing : border-box; } .container { width : 300px; margin : 50px auto; padding : 0 10px; text-align : justify; line-height : 30px; border : 1px solid #000; display : -webkit-box; -webkit-box-orient : vertical; -webkit-line-clamp : 5; overflow : hidden; } </ style>
</ head> < body> < div class = " container" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique, doloribus? Ratione laboreiure, minima voluptatem dolore possimus soluta ea minus tempore animi officia accusantium nulla, maiores,delectus vero debitis recusandae.</ div>
</ body> </ html>
2-2.方法二
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title> < style> * { margin : 0; padding : 0; box-sizing : border-box; } .container { width : 300px; height : 150px; margin : 50px auto; padding : 0 10px; text-align : justify; line-height : 30px; border : 1px solid #000; overflow : hidden; } .container::before { content : '' ; width : 100%; height : 120px; display : block; } .ellipsis { float : right; } .text { margin-top : -120px; } </ style>
</ head> < body> < div class = " container" > < div class = " ellipsis" > ...</ div> < p class = " text" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique, doloribus? Ratione laboreiure, minima voluptatem dolore possimus soluta ea minus tempore animi officia accusantium nulla, maiores,delectus vero debitis recusandae.</ p> </ div>
</ body> </ html>