So I have a table containing two cells and I want to put an element at the center of one cell. It works as expected in Chrome but not in IE or Firefox. Any idea why it is happening? And how can I make it work across browsers?
It seems that in Firefox the left attribute isn't right, it is positioned not to the parent block but to the whole document. And in IE the top attribute doesn't work.
<table style="height:500px;width:500px;table-layout:fixed">
<tr>
<td class='div'>
<span id='divElement'>
We are launching soon!!!!
</span>
</td>
<td style="background-color:red">
</td>
</tr>
</table>
#divElement{
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
width: 100px;
height: 100px;
background-color: blue;
}
.div{
position: relative;
background-color: yellow;
}
Update:
The reason I am not using vertical-align:center is because what I really want to do is actually not just place it in center.
So I have an element placed to center and want to place two elements at fixed offset next to that centered element, one at each side. And I want the offset to be fixed even when window size changes. (The table will take 100% of window and each td takes 50% so when window size changes td size changes too)
The way I came up with is to use absolute positioning and place two elements at center first then use margin to push them by the [width/2 + fixOffset] of the centered element
Maybe there is a better way to do it?