Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center an image in a table td?

I want to center (center+middle) an image, and the title inside h2, in a table column (td)

CSS

.centered
{
    text-align:center;
}

HTML

<table class="table table-bordered">
<tbody>

<tr>
    <td class="centered"><%= image_tag(prank.image_url, :size => "50x50") %></td>
    <td class="centered"><h2><%=prank.category.titleize%></h2></td>
</tr>

enter image description here

I'm using Twitter Bootstrap

like image 890
sparkle Avatar asked Apr 06 '12 12:04

sparkle


2 Answers

You could try:

.centered { vertical-align:middle; text-align:center; }
.centered img { display:block; margin:0 auto; }
like image 120
tim_brook Avatar answered Sep 25 '22 17:09

tim_brook


Try

.centered{width: 50px; margin: 0px, auto, 0px, auto;}
like image 45
Joe Avatar answered Sep 23 '22 17:09

Joe