SOURCE

console 命令行工具 X clear

                    
>
console
<div class="container">
  <div class="content-wrapper">
    <div class="content">

       <!--小图标1(文本超出隐藏后显示)-->
       <span class="icon-1"></span>

       <!--文本内容-->
       <span>测试内容测试内容测试内容测试内容测试内容测试内容测试内容测试内容CSS实现小图标跟随文本(多行文本省略时显示在省略号后面)</span>
      
       <!--小图标2(跟随文本,超出后隐藏)-->
       <span class="icon-2"><span>
           
    </div>
  </div>
</div>


<div class="container">
  <div class="content-wrapper">
    <div class="content">

       <!--小图标1(文本超出隐藏后显示)-->
       <span class="icon-1"></span>

       <!--文本内容-->
       <span>\CSS实现小图标跟随文本(多行文本省略时显示在省略号后面)</span>
      
       <!--小图标2(跟随文本,超出后隐藏)-->
       <span class="icon-2"><span>
           
    </div>
  </div>
</div>
.container{
  width: 200px;
  height: 40px;
  border: 1px solid;
  margin-bottom: 50px;
  background: #fff;
}
/** 必须设置flex布局撑开容器,
**  否则content的before元素高度calc(100% - 18px)不会生效
*/
.content-wrapper{
    width: 100%;
    height: 100%;
    
    font-size: 14px;
    line-height: 20px;
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.content{
    height: 100%;
    width: 100%;
    position: relative;
}

/*撑开高度,确保icon-1位于文本右下方*/
.content::before{
    content: '';
    display: block;
    float: right;
    width: 0px;
    height: calc(100% - 18px);
}

/*用于文本未超出时遮挡icon-1*/
.content::after{
  position: absolute;
  content: '';
  display: inline-block;
  width: 100%;
  height: 100%;
  background: #ffffff;
}

/*文本超出后显示的图标*/
.icon-1{
  height: 16px;
  width: 16px;
  background-size: cover;
  margin-left: 8px;
  float: right;
  clear: both;
  display: block;
  background: red;
}

/*文本未超出时显示的图标*/
.icon-2{
  position: relative;
  display: inline-block;
  height: 16px;
  width: 16px;
  background-size: cover;
  margin-left: 2px;
  transform: translateY(2px);
  background: blue;
}

/*文本未超出,且文本恰巧在某行末尾结束,遮挡处于正下方的icon-1*/
.icon-2::after{
  content: '';
  position: absolute;
  background: #ffffff;
  left: 0px;
  bottom: -40px;
  height: 40px;
  width: 40px;
}