效果图
纯css效果实现
<div class="content_box">
<input type="checkbox" id="exp">
<div class="content word" line-clamp="2">
<label class="btn" for="exp">
<i class="iconfont icondown"></i>
</label>
{{orderInfo.originalContent}}
</div>
</div>
.content_box{
display: flex;
flex: 1;
}
.word{
flex: 1;
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #303133;
line-height: 24px;
overflow: hidden;
// display: -webkit-box;
// -webkit-box-orient: vertical;
// -webkit-line-clamp: 2;
line-height: 1.5; /*根据实际调整行高,最大高度*/
max-height: 3em;
// transition: .3s max-height;
span{
display: inline-block;
}
&::before{
content: '';
float: right;
width: 0px;
height: calc(100% - 21px);
}
&::after {
content: '';
width: 100%;
height: 20px;
position: absolute;
background: #fff;
}
.btn {
color: #3F66FF;
float: right;
clear: both;
margin-top: 0px;
margin-right: 13px;
cursor: pointer;
position: relative;
.icondown{
position: absolute;
bottom: -4px;
right: -17px;
font-size: 18px;
color: #3F66FF;
}
}
.btn::before{
content: '...';
position: relative;
left: -6px;
top: 1px;
color: #303133;
transform: translateX(-100%)
}
.btn::after{
content:'展开' /*采用content生成*/
}
}
// 默认展示二行
[line-clamp="2"] {
max-height: 3em;
}
#exp{
display: none;
}
#exp:checked+.word{
// max-height: none;
max-height: 800px; /*超出最大行高度就可以了*/
}
#exp:checked+.word .btn::after{
content:'收起'
}
#exp:checked+.word .btn::before {
visibility: hidden; /*在展开状态下隐藏省略号*/
}
#exp:checked+.word::after{
visibility: hidden;
}
#exp:checked+.word .btn{
.icondown{
transform: rotate(180deg);
}
}