html - 将图标对齐到 div 元素下方

标签 html css

我有一个 div 元素,里面有一个图标。我想将图标放在 div 元素值的正下方,但它在同一行上水平对齐:

screenshot

.time {
  width: 400px;
  height: 400px;
  border-radius: 50%;
  font-size: 50px;
  color: green;
  line-height: 400px;
  text-align: center;
  margin: auto;
  background: #000;
}
<div class="time" style="vertical-align: middle"
 [style.color]="started ? 'green' : 'red'">
  {{formatTime(time)}}
  <i class="play icon"></i>
</div>

最佳答案

您可以使用 Flexbox 来做到这一点:

.time {
  display: flex; /* displays flex-items (children) inline, that's why you need to change its direction */
  flex-direction: column; /* now stacked vertically */
  justify-content: center; /*  centers them vertically */
  align-items: center; /* and horizontally */
  width: 400px;
  height: 400px;
  border-radius: 50%;
  font-size: 50px;
  color: green;
  /* not necessary
  line-height: 400px;
  text-align: center;
  */
  margin: auto;
  background: #000;
}
<div class="time" [style.color]="started ? 'green' : 'red'">
  {{formatTime(time)}}
  <i class="play icon">&#9658;</i>
</div>

关于html - 将图标对齐到 div 元素下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48084156/

相关文章:

javascript - IE8 绝对/相对定位元素不显示

html - 浏览器刷新行为

jquery - 从 CSS 中的类中删除样式

javascript - 将行为应用于具有相同类的元素中的特定 div

javascript - 查看音频标签并滚动文本

javascript - 无法将我的页面链接到 node.js 中的路由器

html - 双引号打印不正确 |火狐 |拉托字体|

javascript - 在 div 中使用 jquery 无限滚动仅显示 10 个元素

php - docker 上的 Magento 2 - 没有加载 css

Javascript - 文档.createTextNode()