Web实现:多行文本超出省略实例

78 篇文章 2 订阅
68 篇文章 0 订阅

HTML部分:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="./index.css" />
    <title>多行文本溢出省略</title>
  </head>
  <body>
    <div class="container">
      <div class="card">
        <div class="title">
          <div class="author">
            <img src="./images/avattar.jpg" alt="" class="avatar" />
            <span class="name">李西西</span>
          </div>
          <span class="arrow-icon"></span>
        </div>
        <div class="option">
          <span class="heart-icon"></span>
          <span class="option-txt">采纳了你的回答</span>
        </div>
        <div class="txt">
          <span>先说下结果吧,应该是true。由于“()”可以改变运算符的优先级,所以(x!=2)==!(x==2)就相当于 A == !B,其中 A 是x!=2,B 是x==2。A即x!=2,结果是false。B即x==2,结果是true,所以 !B是false。所以 A == !B是true。</span>
        </div>
      </div>
    </div>
  </body>
</html>

CSS部分:

.card {
  border-top: 1px solid #feba64;
  width: 270px;
  padding-bottom: 15px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.title {
  height: 35px;
  padding: 0 12px 0 10px;
  border-bottom: 1px solid #eff0f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.title .author {
  display: flex;
  align-items: center;
}
.title .arrow-icon {
  width: 6px;
  height: 10px;
  background: url(./images/arrow-right.png) no-repeat center / contain;
}
.title .avatar {
  width: 20px;
  height: 20px;
  margin-right: 7px;
  border-radius: 50%;
}
.title .name {
  font-size: 14px;
  color: #9b9b9b;
}
.option {
  margin: 0 10px;
  padding: 11px 0 9px;
  display: flex;
  align-items: center;
}
.option .option-txt {
  font-size: 15px;
  color: #333333;
}
.option .heart-icon {
  width: 16px;
  height: 17px;
  background: url(./images/heart.png) no-repeat center / 14px 13px;
  margin-right: 7px;
}
.txt {
  background: #f6f7f8;
  padding: 5px 4px;
  font-size: 14px;
  color: #808080;
  margin: 0 10px;
}
.txt span {
  /* 隐藏超出部分 */
  overflow: hidden;
  /* 文本超出就用省略号 */
  text-overflow: ellipsis;
  /* 把对象作为弹性伸缩盒子模型显示 */
  display: -webkit-box;
  /* WebKit内核的浏览器的私有属性,设置文本超出2行就用省略号 */
  -webkit-line-clamp: 2;
  /* WebKit内核的浏览器的私有属性,设置或检索伸缩盒对象的子元素的排列方式 */
  -webkit-box-orient: vertical;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jasmyn518

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值