html - 如何通过水平父 block 使图标居中?

标签 html css

我有以下 block :

<div class="class-journal-mobile-navigation-move left">
<i class="material-icons"> arrow_back_ios</i>
</div>

.class-journal-mobile-navigation-move {
    border-radius: 50%;
    border: 1px solid #3e4eb8;
    width: 50px;
    height: 50px;
    display: table;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.class-journal-mobile-navigation-move i {
    font-size: 24px;
    color: #3e4eb8;
    display: table-cell;
    text-align: center;
}

我需要在父 block 中将 i 元素居中,现在它看起来像:

enter image description here

应用更改后,它现在看起来是:

enter image description here

最佳答案

你可以使用 flexbox:

代替显示:表格;对于类日志移动导航移动,

h1, p {
  font-family: Lato;
}

.class-journal-mobile-navigation-move {
      border-radius: 50%;
      border: 1px solid #3e4eb8;
      width: 50px;
      height: 50px;
      /* display: table; */
      cursor: pointer;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;

      display: flex;
      align-items: center;
      justify-content: center;
  }

  .class-journal-mobile-navigation-move i {
      font-size: 24px;
      color: #3e4eb8;
      /* display: table-cell; */
      text-align: center;
  }
  <div class="class-journal-mobile-navigation-move left">
  <i class="material-icons"><</i>
  </div>

关于html - 如何通过水平父 block 使图标居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56398850/

相关文章:

javascript - 如果 href 包含哈希,如何阻止链接?

html - 如何使用 html + Tailwind CSS 使表格可滚动

javascript - 滚动下拉菜单推送内容

html - 单击表体中的链接时,粘性表头会跳转

css - DIV 中的绝对定位

html - 标签在列表标签​​中掉落

javascript - jquery 点击功能不适用于每个输入字段

javascript - HTML5 网络音频 API : Filters is not working

html - CSS 上的不对称背景阴影

html - 将 Div 设置为在屏幕尺寸缩小时移动到另一个 Div 下方