[英]Align Font Awesome icon vertically centred and to left of table
I am trying to position a font-awesome icon to the left of a table element, such that it is vertically centred against the table. 我正在尝试在表格元素的左侧放置一个超棒的字体图标,以使其垂直于表格居中。
This is what I have at the moment: 这是我目前所拥有的:
HTML HTML
<div class="dates">
<i class="fa fa-calendar fa-4x" aria-hidden="true"></i>
<table>
<tbody>
<tr>
<td>24th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>25th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>26th Jul 2018</td>
<td>7PM</td>
</tr>
<tr>
<td>27th Jul 2018</td>
<td>1PM / 7PM</td>
</tr>
</tbody>
</table>
</div>
CSS CSS
.dates {
border: 3px solid black;
display: inline-block;
padding: 8px 0;
border-radius: 10px;
background-color: white;
border-color: grey;
.fa {
vertical-align: middle;
}
table {
display: inline-block;
td {
font-weight: bold;
margin: 0;
padding: 0 10px;
}
}
}
And it's giving me this result: 这给了我这个结果:
Add display: inline-block
and vertical-align: middle
to both the icon and table, like so: 在图标和表格的
vertical-align: middle
添加display: inline-block
和vertical-align: middle
所示:
(For the purposes of the demo I unnested your Sass into normal CSS.) (出于演示目的,我未将Sass嵌套到普通CSS中。)
.dates { border: 3px solid black; display: inline-block; padding: 8px 0; border-radius: 10px; background-color: white; border-color: grey; } .fa { display: inline-block; vertical-align: middle; } table { display: inline-block; vertical-align: middle; } td { font-weight: bold; margin: 0; padding: 0 10px; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /> <div class="dates"> <i class="fa fa-calendar fa-4x" aria-hidden="true"></i> <table> <tbody> <tr> <td>24th Jul 2018</td> <td>7PM</td> </tr> <tr> <td>25th Jul 2018</td> <td>7PM</td> </tr> <tr> <td>26th Jul 2018</td> <td>7PM</td> </tr> <tr> <td>27th Jul 2018</td> <td>1PM / 7PM</td> </tr> </tbody> </table> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.