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>

I'm using Twitter Bootstrap

Answers


You could try:

.centered { vertical-align:middle; text-align:center; }
.centered img { display:block; margin:0 auto; }

N.B. align="center" is not supported in HTML 5; see http://www.w3schools.com/tags/tag_td.asp


Try

.centered{width: 50px; margin: 0px, auto, 0px, auto;}

check this out http://jsfiddle.net/k6Nvk/1/

just add in your <td> >> <td align="center" valign="middle"><image path></td>

and you can also do this using css check DEMO


All you have to do is declare margin from left and right (top and bottom optional):

.center {
margin-left: 25%;
margin-right: 25%;
}

Or you can just use

.center
{
margin-left: auto;
margin-right: auto;
width: 20%;
}

If you don't have to just don't use <table> tag. Use <div> instead.


Here is how I did it. I call the base twitter css file. than after i call my default css file in my default file I have this class

.table-center th, .table-center td {
    border-top: 1px solid #DDDDDD;
    line-height: 18px;
    padding: 8px;
    text-align: center;
    vertical-align: top;
}

then in my table i do this:

<table class="table table-center ....">...</table>

This should work
.cntr
{
        margin: 0 auto;
}

<div class="cntr" style="width: 130px">
         <img src="me.jpg" alt="me"  style="width: 130px" />
</div>

Give this a try, but not 100% sure if it'll work:

.centered {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

I would try text-align: center; in inline style="".


Need Your Help

Can you mass edit all files returned in a grep?

search vim command-line sed grep

I want to mass-edit a ton of files that are returned in a grep. (I know, I should get better at sed).

SQL Server User Mapping Error 15023

sql sql-server

I try to map my other DB to a user by going to Security > Logins > right click someuser > Properties > User Mapping > Select DB > set as db_owner and then ok, but I keep on getting an error saying ...