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>Document</title>
</head>
<body>
  <div class="card">
    <div class="title">当我回家的时候,我的猫跑到我面前,不停喵喵叫,这是什么意思?</div>
    <div class="author">
      <div class="avatar"></div>
      <div class="username">崽崽</div>
      <div class="tag">铲屎官、摄影爱好者、外星人研究中心高级清洁工、双向喵星卧底</div>
    </div>
    <div class="txt">我的天!恭喜你俘虏喵心一颗,它想你这个两脚兽啦!在昨天之前,我以为我的猫崽子是不屑于亲近我的,但是昨天我回家的时候却发现它哈哈哈一直在叫,但我一进门它就不叫了,跑过来蹭我的腿。哈哈。</div>
  </div>
</body>
</html>

CSS部分:

.card {
  width: 320px;
  padding: 10px;
  box-sizing: border-box;
  border: 1px solid #979797;
  background: #f4f4f4;
}
.card .title {
  font-weight: 600;
  font-size: 16px;
  color: #333333;
  margin-bottom: 5px;
}
.card .author {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}
.card .author .avatar {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #d8d8d8;
  margin-right: 5px;
  flex: none;
}
.card .author .username {
  font-weight: 500;
  font-size: 12px;
  color: #666;
  margin-right: 5px;
  flex: none;
}
.card .author .tag {
  font-size: 12px;
  color: #999;
  flex: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.card .txt {
  font-size: 14px;
  color: #333333;
  /* 隐藏超出部分 */
  overflow: hidden;
  /* 文本超出就用省略号 */
  text-overflow: ellipsis;
  /* 把对象作为弹性伸缩盒子模型显示 */
  display: -webkit-box;
  /* WebKit内核的浏览器的私有属性,设置文本超出2行就用省略号 */
  -webkit-line-clamp: 2;
  /* WebKit内核的浏览器的私有属性,设置或检索伸缩盒对象的子元素的排列方式 */
  -webkit-box-orient: vertical;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

jasmyn518

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

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

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

打赏作者

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

抵扣说明:

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

余额充值