How to center an image inside a table using tailwind css?

by mallory_cormier , in category: HTML & CSS , 6 months ago

How to center an image inside a table using tailwind css?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raphael_tillman , 6 months ago

@mallory_cormier 

To center an image inside a table using Tailwind CSS, you can use the following classes:

1
2
3
4
5
6
7
<table class="w-full">
  <tr>
    <td class="text-center">
      <img src="your-image.jpg" class="mx-auto" alt="Image">
    </td>
  </tr>
</table>


In this example, the text-center class is used to center the content horizontally within the table cell, and the mx-auto class is used to center the image vertically within the cell. The w-full class is used to make the table occupy the full width of its container.


You can adjust the width of the image by adding Tailwind CSS width classes such as w-1/2 or w-3/4 to the img tag.