纯css实现多行省略,末尾展示更多按钮
html代码片段:
1 ### vue2 Template ### 2 <div class="wrapper"> 3 <input :id="`fold-btn-${id}`" class="exp" type="checkbox" /> 4 <div :ref="'workDetailRef' + id" class="text"> 5 <label class="btn" :for="`fold-btn-${id}`"></label>{{ workDetail }} 6 </div> 7 </div> 8
css样式:
1 .wrapper { 2 padding: 3px 8px; 3 display: flex; 4 width: 100%; 5 overflow: hidden; 6 background: #eee; 7 } 8 .text { 9 font-size: 12px; 10 color: #2c2c2c; 11 overflow: hidden; 12 text-overflow: ellipsis; 13 text-align: justify; 14 position: relative; 15 line-height: 22px; 16 max-height: 44px; 17 transition: 0.3s max-height; 18 } 19 .text::before { 20 content: ''; 21 height: calc(100% - 22px); 22 float: right; 23 } 24 .text::after { 25 content: ''; 26 width: 999vw; 27 height: 999vw; 28 position: absolute; 29 box-shadow: inset calc(100px - 999vw) calc(20px - 999vw) 0 0 #eee; 30 margin-left: -100px; 31 } 32 .btn { 33 position: relative; 34 float: right; 35 clear: both; 36 margin-left: 20px; 37 font-size: 12px; 38 padding: 0 8px; 39 background: #307cfb; 40 line-height: 22px; 41 border-radius: 2px; 42 color: #fff; 43 cursor: pointer; 44 } 45 .btn::after { 46 content: '查看更多'; 47 } 48 .exp { 49 display: none; 50 background: #eee; 51 } 52 .exp:checked + .text { 53 max-height: none; 54 } 55 .exp:checked + .text::after { 56 visibility: hidden; 57 } 58 .exp:checked + .text .btn::before { 59 visibility: hidden; 60 } 61 .exp:checked + .text .btn::after { 62 content: '收起'; 63 } 64 .btn::before { 65 content: '...'; 66 position: absolute; 67 bottom: -3px; 68 left: -8px; 69 color: #2c2c2c; 70 transform: translateX(-100%); 71 }

浙公网安备 33010602011771号