在可变高度的td中垂直对齐字体真棒图标

时间:2015-03-03 18:22:03

标签: html css twitter-bootstrap-3 vertical-alignment font-awesome

我需要在td的中间垂直对齐字体真棒图标。此td可以包含单行或双行文本,因此它具有可变高度。我只是无法弄清楚如何对齐它。我尝试了从line-heightvertical-aligndisplay: inline-table的所有内容。没有任何效果。也许你有个主意。

我在谈论fa-tags图标。这是我的代码:

HTML:

<table>
  <tbody class="row">
    <tr class="data">
      <td class="date">
        <span class="fa fa-tags"></span>
        <div class="time">
          <time datetime="2015-04-21">21.04.2015</time> -<br>
          <time datetime="2015-04-24">24.04.2015</time>
        </div>
      </td>
      <td class="hotel-data">
        Hilton Barcelona
        <span class="stars">
          <span class="fa fa-star"></span>
          <span class="fa fa-star"></span>
          <span class="fa fa-star"></span>
          <span class="fa fa-star"></span>
        </span>
      </td>

      <td class="contract">
        <a href="#" title="Vertrag runterladen">Vertrag <span class="fa fa-fw fa-download"></span></a>
      </td>
      <td class="invoice">
        <a href="#" title="Rechnungen runterladen">Rechnungen <span class="fa fa-fw fa-download"></span></a>
      </td>
      <td class="details">
        <a href="" title="">Details <span class="fa fa-chevron-right fa-fw"></span></a>
      </td>
    </tr>
    <tr class="data">
      <td class="date">
        <span class="fa fa-tags"></span>
        <div class="time">
          <time datetime="2015-04-21">21.04.2015</time>
        </div>
      </td>
      <td class="hotel-data">
        Best Western Alfa Aeropuarto Barcelona
        <span class="stars">
          <span class="fa fa-star"></span>
          <span class="fa fa-star"></span>
          <span class="fa fa-star"></span>
          <span class="fa fa-star"></span>
        </span>
      </td>

      <td class="contract">
        <a href="#" title="Vertrag runterladen">Vertrag <span class="fa fa-fw fa-download"></span></a>
      </td>
      <td class="invoice">
        <a href="#" title="Rechnungen runterladen">Rechnungen <span class="fa fa-fw fa-download"></span></a>
      </td>
      <td class="details">
        <a href="" title="">Details <span class="fa fa-chevron-right fa-fw"></span></a>
      </td>
    </tr>
  </tbody>               
  </table>

CSS:

td {
    padding: 7px 15px;
    vertical-align: middle;
    min-height: 57px;
}
.date .fa {
    color: #999;
    font-size: 18px;
    margin-right: 5px;
}
.time {
    display: inline-block;
    font-size: 13px;
    color: #d91e17;
}

EXAMPLE BOOTPLY

1 个答案:

答案 0 :(得分:4)

看起来您只需要将vertical-align: middle添加到.time元素即可。这样,兄弟.fa-tags元素将垂直居中。

Updated Example

.time {
    display: inline-block;
    vertical-align: middle;
    font-size: 13px;
    color: #d91e17;
}