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?
I think table-cell
needs to have a parent display:table
element.
This is how I do it:
CSS:
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
display: table
}
#content {
display: table-cell;
text-align: center;
vertical-align: middle
}
HTML:
<div id="content">
Content goes here
</div>
See
Example of vertical centering
and
CSS: centering things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With