单行
div {
width: 350px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
多行
div {
width: 350px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2; // 显示的行数
overflow: hidden;
}
无固定宽度
<!DOCTYPE html>
<html>
<head>
<style>
.listWrap{
display: flex;
width: 200px;
}
.ellipsis {
display: flex;
flex-direction: row;
align-items: center;
overflow: hidden;
}
.date{
flex-shrink: 0;
}
.ellipsis-content {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="listWrap">
<div class="ellipsis">
<div class="ellipsis-content">This is a long text that will be truncated with an ellipsis if it exceeds one line.</div>
</div>
<div class="date">2023-02-02</div>
</div>
</body>
</html>