文字超过两行省略

今天遇见一个问题就是要对文字超过两行进行省略,并进行弹窗
换行代码

			overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;

对应换行弹窗代码

css 
.content{
            float: left;
            margin: 50px 50%;
            transform: translateX(-50%);
            width: 60%;
            height: auto;
            background: #666;
            border-radius: 10px;
 }
 .content span{
            display: inline-block;
            width: 8%;
            margin: 20px 17px;
            position: relative;
            height: 43px;
 }
.topContent {
            position: absolute;
            top: -80%;
            left: 50%;
            background: #fff;
            color: #000;
            z-index: 900;
            border-radius: 5px;
}
html
<div class="content">
	<span>
          <p>大数据大数4124124124据</p>
    </span>
</div>
js
//弹窗方法
let content = document.getElementsByClassName("content")
      for(let i = 0; i < content[0].children.length; i++){
          let child = content[0].children[i]
          if(child.scrollHeight > child.clientHeight){
              console.log(1)
              child.children[0].classList.add("ellipsis")
              console.log(child.classList)
              let div = document.createElement("div")//创建弹窗
              child.children[0].onmouseover = function(){
                  child.appendChild(div)
                  div.textContent = this.textContent
                  div.classList.add('topContent')
              }
              child.children[0].onmouseout = function(){
                  child.removeChild(div)
              }
          }
}

并未对样式进行细细琢磨,有什么问题,可以共同探讨

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值