html - ngFor <il> 循环中的右对齐图标

标签 html css

将创建一个元素列表并在右侧对齐图标。

<ul class=" list">
   <li *ngFor="let group of groupList">
      <div class="list-item"><span>{{ group.name }} (ID {{group.code}} ) </span></div>
      <div class="trash-icon">
          <img src="assets/img/icon_trash.png" height="20" width="20"/>
      </div>
    </li>
</ul>

在 CSS 中:

.list-item {
    width: 300px;
    display : inline-block;
}
.trash-icon {
    float: right;
} 
.trash-icon::after {
    clear: both;
}

第一行对齐正确,但后面的行缩进了。

截图如下:

enter image description here

当我用右对齐替换 float 时:

enter image description here

最佳答案

为此使用 flexbox 显示。

<ul class="list">
   <li *ngFor="let group of groupList">
      <div class="list-item"><span>{{ group.name }} (ID {{group.code}} ) </span></div>
      <div class="trash-icon"><img src="assets/img/icon_trash.png" height="20" width="20"/></div>
    </li>
</ul>

你的风格

ul.list li {
  display: flex;
  justify-content: center;
}

ul.list li div.list-item {
  flex: 1 1 auto;
}

ul.list li div.trash-icon {
  flex: 0 0 20px;
}

关于html - ngFor <il> 循环中的右对齐图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49431633/

相关文章:

javascript - 菜单卡住,无法点击

javascript - 如何使用 jQuery/Javascript 隐藏 anchor 标记之前的元素?

javascript - HTML5 验证的表单事件失败?

css - 如何在 h1 背景中垂直居中跨度

javascript - 如何用 html 元素替换粗体、下划线等文本?

javascript - 固定菜单不起作用(菜单不 "stick")

python - 你如何在 Django 中使用下载的模板

jquery - 在 jquery 中使用 chrome 开发人员工具调试 Dom 异常

android - Android 上是否有 "add to homescreen"webapp(就像在 iOS 中一样)

javascript - 使用 Javascript 进行高级过滤