html - css - 如何在 td 中居中 Font Awesome 图标?

标签 html css font-awesome

我正在为我的图标和一个简单的表格使用 font-awesome。

如何让这个图标位于 td 的中心? 我尝试使用 text-align: center,但没有成功。

有人知道如何解决这个问题?

谢谢。

jsfidle:https://jsfiddle.net/s15dxabc/

table i {
  color: red;
  background: #ffffff;
  border-radius: 20px;
  padding: 5px 0;
  width: 30px;
  margin-right: 5px;
  border: 2px solid black;
  text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<table>
  <thead>
    <tr>
      <td> this icon should be in the center</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><i class="fa fa-minus"></i></td>
    </tr>
  </tbody>
</table>

最佳答案

td中使用align:center属性

table i {
  color: red;
  background: #ffffff;
  border-radius: 20px;
  padding: 5px 0;
  width: 30px;
  margin-right: 5px;
  border: 2px solid black;
  text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<table>
  <thead>
    <tr>
      <td> this icon should be in the center</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td align="center"><i class="fa fa-minus"></i></td>
    </tr>
  </tbody>
</table>

或者 td css 中的 text-align:center

table i {
  color: red;
  background: #ffffff;
  border-radius: 20px;
  padding: 5px 0;
  width: 30px;
  margin-right: 5px;
  border: 2px solid black;
}
table td {  
  text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<table>
  <thead>
    <tr>
      <td> this icon should be in the center</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td align="center"><i class="fa fa-minus"></i></td>
    </tr>
  </tbody>
</table>

关于html - css - 如何在 td 中居中 Font Awesome 图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45834706/

相关文章:

css - 自定义复选框在 Firefox 上不起作用

css - 更改 primefaces 中的 FontAwesome 图标大小(p :commandButton and p:menuitem)

html - 这个 CSS 有什么问题?添加更多内容时不会达到 100%?

javascript - 复杂的网站,需要更新与 jQuery 共享类的按钮

css - 无需 js/jquery 即可触发关键帧动画

css - bootstrap form-inline 在一行中显示字段

ReactJs 覆盖 Font Awesome 图标

html - CSS:让 "overflow: hidden"隐藏顶部而不是底部?

javascript - 使用 jQuery 打开链接并自动滚动到特定的 div

javascript - 仅在全屏模式下显示页面滚动