简体   繁体   中英

vertically align font awesome icon in td with variable height

I need to vertically align a font-awesome icon in the middle of a td . This td can contain a single or a double line of text, so it has a variable height. I just can't figure out how to align it. I tried everything from line-height over vertical-align to display: inline-table . Nothing worked. Maybe you have an idea.

I'm talking about the fa-tags icon. Here is my code:

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

It looks like you just need to add vertical-align: middle to the .time element. In doing so, the sibling .fa-tags elements will be vertically centered.

Updated Example

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM