Align a Font Awesome icon vertically within a table cell that has a dynamic height

How can I vertically align a font-awesome icon in the center of a td? The td may have varying heights due to its content, which could be one or two lines of text. I've tried adjusting the line-height, using vertical-align, and even applying display: inline-table, but nothing seems to work. Any suggestions would be greatly appreciated.

I'm specifically referring to the fa-tags icon within 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="Download Contract">Contract <span class="fa fa-fw fa-download"></span></a>
      </td>
      <td class="invoice">
        <a href="#" title="Download Invoices">Invoices <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="Download Contract">Contract <span class="fa fa-fw fa-download"></span></a>
      </td>
      <td class="invoice">
        <a href="#" title="Download Invoices">Invoices <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;
}

View Example on Bootply

Answer №1

To achieve vertical alignment for the sibling elements, simply add vertical-align: middle to the .time class. This will center the .fa-tags elements as desired.

See Updated Example Here

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjustable div element and percentage-based height are not functioning correctly

I am facing a minor issue while attempting to create a responsive div with an image background. The div does not match the size of the image: 540px-290px When I resize the browser, the two divs do not resize together. In each div, there is a background ...

Empower the user with the ability to interact through touch on dynamically

I am trying to make a div touchable and draggable. I have dynamically created 1 to 10 divs within another div. Currently, these divs can only be dragged using the mouse or cursor. However, I want to enable dragging through touch as well. Can anyone provi ...

gather data from a separate HTML document's form

Within an html file, users fill out a form and database queries are executed to display Google Maps locations. My objective is to store this data in a variable so that it can be used in another html file. This second html file will utilize the previous va ...

Tips for creating a Bootstrap 5 navbar dropdown menu that opens on hover for desktop users and on click for mobile users

Just starting out in the world of Web Development, so any help would be greatly appreciated! I've been working on a Wordpress website for a company and encountered an issue with my CSS while implementing the Bootstrap 5 navbar. On desktop, the dropdo ...

Difficulty in pinpointing hyperlinks within a styled list

My current challenge involves customizing the color of links within the <li> elements by applying specific classes to the <li> tag. The structure of my HTML is as follows: <div id="sidebar_tall"> <ul> <li class="active_item"> ...

Will images still be loaded within a hidden div in Bootstrap 3?

Creating a responsive website that features a large carousel with multiple images on the homepage. My goal is to optimize image sizes for each device so that only the necessary image is downloaded, conserving bandwidth for mobile users. To achieve this, ...

Is it possible to utilize hCard for semantic markup exclusively for a business's contact information?

Can hCard be used to markup a business's contact information without including a personal name? According to the hCard guidelines, a name is required in the format (e.g. John Doe): . I am specifically trying to mark up just a business's contact d ...

What is the reason that my link to test.xls is functioning properly but the one to the .txt file is not working?

I am facing an issue with downloading files from a folder named Test. In this folder, I have various file types such as .xls, .txt, and .doc files. Within the html code, I have specified download links for these files: <p> <a href="../../Test/St ...

Prevent side-to-side scrolling on elements that exceed the width of the screen

I am working on building a navigation system similar to Google Play, where there are fixed tabs for browsing through the app. I have created a container div that holds various content sections. <div id="container"> <div class="section"> .. ...

I'm looking for a CSS layout that can change the order of columns in a row stack for desktop view. Can anyone help me with this? (refer to

I am struggling with arranging elements in HTML and CSS. As a beginner, I am faced with the challenge of ordering desktop and mobile layouts differently. The current code I am using looks like this: <div class="row "> <div class=&quo ...

Enhance Your Website by Integrating Slick Slider with Bootstrap 4

I am currently facing a significant issue. I am attempting to integrate three div elements into my slider, and all of them maintain a Bootstrap 4 structure. The code looks like this, and it is being generated from another Jquery function where I am inserti ...

Troubleshooting Problem with Matching Heights in Bootstrap Columns

I am experiencing an issue with the bootstrap grid columns on my site not having equal heights. The problem arises when a product name contains a long text, causing height discrepancies among the columns. Despite trying to fix the height issue by adding tw ...

Compiling a list of products, but the user interface needs some adjustments

Currently, I have designed a product list menu that includes a hover dropdown feature. This means that when a user hovers over a specific menu item, the corresponding list will automatically appear. However, I am facing two issues with this setup. Firstly, ...

Fully conceal a DIV while the webpage is loading

Following the header, I've implemented a hidden div with a height transition that can be activated by a button. However, there seems to be an issue where the browser displays the content of the div while the page is loading and then hides it afterward ...

Incorporate various style components to enhance the appearance of an item in ExtJS

I'm attempting to add ellipsis to an item created by ExtJS. My goal is to only modify this item without adding any additional CSS files. After researching, I discovered there is a "style" parameter that accepts CSS styles and attempted the following: ...

Adding additional elements to a div in a horizontal orientation

I am currently working on a project where I need to display bars and restaurants based on specific filter criteria. I have a container div called .resultsContainer where all the results will be displayed. While I can easily append more divs (.barContainer) ...

Animation of CSS elements sliding up on the page, with the element briefly appearing before the slide begins

My CSS animation involves a page scrolling from the bottom to the top when selected. The problem I'm facing is that the page briefly appears in its top position before disappearing to scroll from the bottom to the top. How can I prevent the page from ...

The div should remain at the top after the animation effect, instead of returning to its initial position when moving from the bottom to the top using CSS

I have successfully applied an animation effect to a div tag. Initially, the div is positioned at the bottom, but with the CSS animation effect, it moves to the top. However, after reaching the top position, it reverts back to the bottom. I want it to st ...

A more sophisticated approach to button creation, such as utilizing a single HTML element

Trying to find a sleeker way to create the following HTML button. https://i.sstatic.net/Eanuy.png Currently using an <a href="..."> with 2 child <span> elements like this: - <a href=""> <span class="box_button">Read more</ ...

How can we use jQuery to animate scrolling down to a specific <div> when clicking on a link in one HTML page and then navigating to another HTML page?

I'm currently working on creating a website for my friend who is a massage therapist. Utilizing a bootstrap dropdown menu, I have added links to different treatments that direct to the treatment.html from the index.html page. Is there a way to creat ...