.ellipsis-1 {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
white-space: nowrap 強制不換行。overflow: hidden 切掉溢出部分。text-overflow: ellipsis 顯示「…」標記。table { table-layout: fixed; width: 100%; }
th, td {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
table-layout: fixed 讓欄寬由 `
.ellipsis-3 {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3; /* 顯示 3 行 */
overflow: hidden;
}
支援:Chrome、Edge、Firefox 68+、Safari、Opera。不支援 IE。
.ellipsis-clamp {
line-height: 1.5;
max-height: 4.5em; /* 3 行 = 1.5 * 3 */
overflow: hidden;
position: relative;
}
.ellipsis-clamp::after {
content: '...';
position: absolute;
right: 0; bottom: 0;
padding-left: 0.5em;
background: linear-gradient(to right, transparent, white 50%);
}
利用漸層遮罩實現「漸隱+省略號」,相容性極佳,但需固定行高且背景為純色。
需精確控制行數、支援 HTML 標籤、或舊瀏覽器時,仍建議使用成熟 JS 庫。