css - 文本溢出省略
单行
| @mixin text_ellipsis() { |
| white-space: nowrap; |
| overflow: hidden; |
| text-overflow: ellipsis; |
| } |
多行省略
| @mixin text_ellipsis_n($n: 2) { |
| display: -webkit-box; |
| -webkit-box-orient: vertical; |
| -webkit-line-clamp: $n; |
| overflow: hidden; |
| } |
ie
| @mixin text_ellipsis_n($n: 2) { |
| display: -webkit-box; |
| -webkit-box-orient: vertical; |
| -webkit-line-clamp: $n; |
| overflow: hidden; |
| } |

float布局
| |
| |
| |
| |
| |
| |
| |
| |
| <!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> |
| </head> |
| <style> |
| .height-fixed { |
| height: 40px; |
| overflow: hidden; |
| line-height: 20px; |
| } |
| .height-fixed .text { |
| float: right; |
| width: 100%; |
| margin-left: -5px; |
| word-break: break-all; |
| } |
| .height-fixed::before { |
| float: left; |
| width: 5px; |
| content: ''; |
| height: 100%; |
| } |
| .height-fixed::after { |
| float: right; |
| content: '...'; |
| height: 20px; |
| line-height: 20px; |
| width: 16px; |
| |
| margin-left: -40px; |
| padding-left: 24px; |
| |
| padding-right: 5px; |
| position: relative; |
| left: 100%; |
| top: -20px; |
| background: -webkit-linear-gradient(left, transparent, #fff 50%); |
| background: -o-linear-gradient(right, transparent, #fff 50%); |
| background: -moz-linear-gradient(right, transparent, #fff 50%); |
| background: linear-gradient(to right, transparent, #fff 50%); |
| } |
| </style> |
| <body> |
| <div class="height-fixed"> |
| <div class="text"> |
| 这段文字很长这段文字很长这段文字很长这段文字很长这段文字很长这段文字很 |
| 长这段文字很长这段文字很长这段文字很长这段文字很长这段文字很长 |
| </div> |
| </div> |
| </body> |
| </html> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步