tags:

views:

17

answers:

2

I am trying to simply center text horizontally and vertically using DIV and display type as table-cell but it is not working in either IE8 or Firefox.

Below is the CSS that I am using and that is all that is in the html page.

@charset "utf-8";
/* CSS Document */
html, body
{
    background-color:#FFFFFF;
    font-family:Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;
    padding-top: 5px;
}
div.Main
{
    background-color:#FFFFFF;
    border-collapse:collapse;
    width:800px;
    margin-left:auto;
    margin-right:auto;
}
div.MainHeader
{
    color:#C00000;
    font-size:18pt;
    font-weight:bold;
    text-align:center;
    width:800px;
}
div.BlackBox
{
    background-color:#000000;
    color:#FFFF00;
    display:table-cell;
    float:left;
    font-size:18pt;
    font-weight:bold;
    height:191px;
    text-align:center;
    vertical-align:middle;
    width:630px;
}
div.BlackBoxPicture
{
    background-color:#000000;
    float:right;
    height:191px;
    margin-top:auto;
    margin-bottom:auto;
    text-align:right;
    vertical-align:bottom;
    width:170px;
}

What am I doing wrong?

A: 

I think table-cell needs to have a parent display:table element.

meder
And, possibly, a `display: table-row` element between them.
David Thomas
Nope that didn't do the job
mattgcon
Wait.. you have them floated. Remove the float? Please post a jsfiddle. You may want to use `inline-block` instead. It helps seeing the visuals, though.
meder
@mattgcon, `display: table-cell` works, and allows `vertical-align` to be used in both Chrome and Firefox without any issues (on Ubuntu 10.10): [JS Fiddle demo](http://jsfiddle.net/davidThomas/8At93/). Using `float` on the `display: table-cell` elements does, however, break that ability it seems: [JS Fiddle demo with `float`](http://jsfiddle.net/davidThomas/8At93/1/)
David Thomas
No dice, I need float
mattgcon
A: 

This is fixed by putting a table within the div

mattgcon
Is this not the same thing as my answer?
meder