https://jsfiddle.net/g0Lf42bq/6/#&togetherjs=khq05DeHEp

我有一个包含文本+图标的div

(所需的行为就像在GMAIL收件箱中,当鼠标悬停在邮件上时,图标会显示出来,文本是省略号)

目前,文本不是省略号,我看不到所有的图标

.selected-field-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-section {
  display: flex;
  justify-content: space-between;
  background: #FFFFFF;
  border: 1px solid #CCCED3;
  box-sizing: border-box;
  border-radius: 2px;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: #37383A;
  padding: 6px;
  margin-top: 10px;
  width: 195px;
  max-width: 195px;
}

.remove-field {
  display: none;
}

.field-section:hover .remove-field {
      display: flex;    
}
<div class="field-section">
  <div class="selected-field items-center">
    <div class="selected-field-name">{{selectedField.name}}</div>
  </div>
  <div class="d-flex">
    <icon-button class="remove-field" Icon="plus" width="16px" height="16px" (click)="removeField(selectedField)"></icon-button>
    <icon-button class="remove-field" Icon="x-close" width="16px" height="16px" (click)="removeField(selectedField)"></icon-button>
  </div>
</div>

推荐答案

.selected-field的基础上再加overflow: hidden

.selected-field{
   overflow: hidden;
}

工作示例:

.selected-field-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-section {
  display: flex;
  justify-content: space-between;
  background: #FFFFFF;
  border: 1px solid #CCCED3;
  box-sizing: border-box;
  border-radius: 2px;
  font-weight: 400;
  font-size: 12px;
  line-height: 14px;
  color: #37383A;
  padding: 6px;
  margin-top: 10px;
  width: 195px;
  max-width: 195px;
}

.remove-field {
  display: none;
  background: red;
  color: white;
 }

.field-section:hover .remove-field {
   display: flex;    
}

.selected-field{
   overflow: hidden;
}

.icon-wrap{
  display: flex;
  white-space: nowrap;
  gap: 10px
}
<div class="field-section">
  <div class="selected-field items-center">
    <div class="selected-field-name">hello how are you today?</div>
  </div>
  <div class="d-flex icon-wrap">
    <div class="remove-field" Icon="plus" width="16px" height="16px" (click)="removeField(selectedField)">Plus icon</div>
    <div class="remove-field" Icon="x-close" width="16px" height="16px" (click)="removeField(selectedField)">Close icon</div>
  </div>
</div>

Html相关问答推荐

如何防止下拉菜单内的Bootstrap列表行包装?

我的表的第一列似乎是推其他2列到右边,我不能改变它

在CSS中不保持圆形图像形状的边框半径属性

网格容器中的定心元件

有没有可能设置div的边框宽度相对于其父宽度和高度?'

将弹性容器设置为内容宽度

在NzMessageService中传递动态TemplateRef- Angular 15

用于删除页面页眉上的超链接的CSS

SCSS动画错误:心脏在页面刷新时启动动画,原因是:Checked和:Not(:Checked) Select 器

Vutify中看不见的V行

如何使元素具有粘性

我的 *ngFor 中的 array.reverse() 在生产中不起作用

Web 组件 #shadow-root css 泄漏到文档

表单中如何分别禁用/启用多个提交按钮?

如何使用动画拆分和对齐文本块

什么没有 margin-right 和 width:100% 溢出子元素到左边?