htmlMethods to set the excess part not to be displayed: 1. By setting "width:10em;" to ensure that the text will not be truncated by half-Chinese characters; 2. By setting "overflow: hidden;" to hide the text that exceeds the length ;3. Set the ellipsis through "text-overflow:ellipsis;".
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
How to set the excess part not to be displayed in html?
HTML settings exceed the part to be hidden
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ width: 10em; /*保证文字不会被半汉字截断,显示10个文字*/ overflow: hidden; /*超出长度的文字隐藏*/ text-overflow:ellipsis;/*文字隐藏以后添加省略号*/ white-space: nowrap; /*强制不换行*/ } </style> </head> <body> <div> 文字超出了需要隐藏并显示省略号这个在工作中很多时候都要用到,我想很多人都碰到过吧,这个有两种解决方法 </div> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ width: 10em; /*保证文字不会被半汉字截断,显示10个文字*/ overflow: hidden; /*出现省略号*/ text-overflow: ellipsis; /*是在第几行*/ -webkit-line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; } </style> </head> <body> <div> 文字超出了需要隐藏并显示省略号这个在工作中很多时候都要用到,我想很多人都碰到过吧,这个有两种解决方法 </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ width: 10em; /*保证文字不会被半汉字截断,显示10个文字*/ overflow: hidden; /*超出长度的文字隐藏*/ text-overflow:ellipsis;/*文字隐藏以后添加省略号*/ white-space: nowrap; /*强制不换行*/ } </style> </head> <body> <div> 文字超出了需要隐藏并显示省略号这个在工作中很多时候都要用到,我想很多人都碰到过吧,这个有两种解决方法 </div> </body> </html>
Recommended learning: "css video tutorial"
The above is the detailed content of How to set the excess part not to be displayed in html. For more information, please follow other related articles on the PHP Chinese website!