实现查看更多功能 -记录一下可复用

<div :class="[{'box': item.handleText.length > 200 && expandFlag != index }, 'words']" :content="item.handleText">
   {{item.handleText}}
   <span class="btn" @click="expandFlag = index" v-if="item.handleText.length > 200 && expandFlag != index">查看更多</span>
   <span class="btn" @click="expandFlag = -1" v-else-if="item.handleText.length > 200">收起</span>
</div>

利用content 把上面三行内容覆盖拼接

.words{
   position: relative;
   left:0;
   width: 100%;
   line-height: 20px;
 }
 .box{
   max-height:80px;
   color: #fff;
 }
 .box::before, .box::after{
   content: attr(content);
   overflow: hidden;
   position: absolute;
   width: 100%;
   left: 0;
   top: 0;
   color: #666;
   line-height: 20px;
 }
 .box::before{
   max-height: 60px;
   z-index: 2;
   background: #fff;
 }
 .box::after{
   display: -webkit-box;
   -webkit-box-orient: vertical;
   -webkit-box-sizing: border-box;
   box-sizing: border-box;
   -webkit-line-clamp: 4;
   text-indent: -5em;
   padding-right: 5em;
 }
 .words .btn{
   position: absolute;
   right: 8px;
   bottom: -1px;
   z-index: 3;
   color: #1471fc;
   line-height: 20px;
   &:hover{
     cursor: pointer;
   }
 }

在这里插入图片描述

在这里插入图片描述

方法二(纯css)

<div class="wrapper">
  <input id="exp1" class="exp"  type="checkbox">
        <div class="text">
            <label class="btn" for="exp1"></label>
            浮动元素是如何定位的
正如我们前面提到的那样,当一个元素浮动之后,它会被移出正常的文档流,然后向左或者向右平移,一直平移直到碰到了所处的容器的边框,或者碰到另外一个浮动的元素。
在下面的图片中,有三个红色的正方形。其中有两个向左浮动,一个向右浮动。要注意到第二个向左浮动的正方形被放在第一个向左浮动的正方形的右边。如果还有更多的正方形这样浮动,它们会继续向右堆放,直到填满容器一整行,之后换行至下一行。
        </div>
    </div>
.wrapper {
  display: flex;
  margin: 50px auto;
  width: 800px;
  overflow: hidden;
  border-radius: 8px;
  padding: 15px ;
  box-shadow: 20px 20px 60px #bebebe,
    -20px -20px 60px #ffffff;
}
.text {
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: justify;
  /* display: flex; */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  position: relative;
}
.text::before {
  content: '';
  height: calc(100% - 24px);
  float: right;
}
.text::after {
  content: '';
  width: 999vw;
  height: 999vw;
  position: absolute;
  box-shadow: inset calc(100px - 999vw) calc(30px - 999vw) 0 0 #fff;
    margin-left: -100px;
}
.btn{
  float: right;
  clear: both;
  margin-left: 10px;
  font-size: 16px;
  padding: 0 8px;
  background: #3F51B5;
  line-height: 24px;
  border-radius: 4px;
  color:  #fff;
  cursor: pointer;
  /* margin-top: -30px; */
}
.btn::before{
  content:'展开'
}
.exp{
  display: none;
}
.exp:checked+.text{
  -webkit-line-clamp: 999;
}
.exp:checked+.text::after{
  visibility: hidden;
}
.exp:checked+.text .btn::before{
  content:'收起'
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值