作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的图标和一个简单的表格使用 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/
我是一名优秀的程序员,十分优秀!