Question

I'm going off my rocker with IE/CSS problems! I've tried everything (I think) is imaginable to center the text of a table cell. I started with the old, archaic method:

<tr>
    <th width="100" align="center" class="centerme">Some text here.</th>
</tr>

Then, I tried CSS:

.centerme {text-align:center;margin:0 auto;}

Then I tried putting the style inline (keeping ALL the other methods already mentioned):

<tr>
    <th width="100" align="center" class="centerme" style="text-align:center;">Some text here.</th>
</tr>

What could I possibly be missing? I tried center aligning the <tr> element, which shouldn't make a difference, but then IE is a nightmare to get along with! Note this is only a problem in IE. It is fine in every other browser (and this is IE 8)

Was it helpful?

Solution

Removing the width="100" resolved the issue.

OTHER TIPS

Try this:

td 
{
    height: 50px; (or whatever value you want)
    width:50px;
 }

 #cssTable td 
{
    text-align:center; 
    vertical-align:middle;
}

Try this code. I was able to get it to work.

The margin centers the table on the screen. So delete it if you do not want it to be centered.

Change the width to whatever you desire. Right now it is 100% for the whole width of the screen.

HTML:

<table border="1">
    <tr>
        <td>row 1, cell 1</td>
        <td>row 1, cell 2</td>
    </tr>
    <tr>
        <td>row 2, cell 1</td>
        <td>row 2, cell 2</td>
    </tr>
</table> 

CSS:

table, th, td
{
border: none;
margin:0px auto;
text-align:center;
}

table{
width:50%;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top