1. 内容是单行时
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8">
- <style type="text/CSS">
- *{
- padding: 0;
- margin: 0;
- }
- .dit{
- width: 300px;
- height: 200px;
- margin: 0 auto;
- border: 1px solid red;
- }
- .singleLine{
- width: 250px;// 控制超过此宽度后, 显示省略号
- display: block;
- text-overflow: ellipsis;
- overflow: hidden;
- white-space: nowrap;
- }
- </style>
- </head>
- <body>
- <p class="dit">
- <a class="singleLine" href="#"> 中华人民共和国中华人民共和国中华人民共和速度收到收到是货运公司的人 </a>
- </p>
- </body>
- </html>
2. 内容是多行时:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- <style type="text/css">
- .test{
- width: 80px;
- height: 55px;
- border: 1px solid red;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 3;// 控制显示的行数
- -webkit-box-orient: vertical;
- }
- </style>
- </head>
- <body>
- <p class="test">
收到回复让他让地地道道的但是的二胡都让让如果动画收到和动画哦 i 的话
- </p>
- </body>
- </html>
来源: https://www.2cto.com/kf/201806/753936.html