float 特性实现多行文本截断

.wrap {

  height: 40px;

  line-height: 20px;

  overflow: hidden;

}

.wrap .text {

  float: right;

  margin-left: -5px;

  width: 100%;

  word-break: break-all;

}

.wrap::before {

  float: left;

  width: 5px;

  content: '';

  height: 40px;

}

.wrap::after {

  float: right;

  text-align: right;

  content: "...";

  height: 20px;

  line-height: 20px;

  /* 为三个省略号的宽度 */

  width: 20px;

  /* 使盒子不占位置 */

  margin-left: -20px;

  background: -webkit-gradient(linear, left top, right top, from(rgba(255, 255, 255, 0)), to(white), color-stop(100%, white));

  background: -moz-linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);

  background: -o-linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);

  background: -ms-linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);

  background: linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);

  /* 移动省略号位置 */

  position: relative;

  left: 100%;

  top: -20px;

  padding-right: 5px;

}


<div class="wrap">

<div class="text">是不是也能输入中文来测试测试是不是也能输入中文来测试测试是不是也能输入中文来测试测试是不是也能输入中文来测试测试是不是也能输入中文来测试测试</div>

</div>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容