Possible Duplicate:
css vertical centering
I'd forgotten just how difficult it is to center things in CSS.
In the attached code I am trying to vertically align both the Image and the TitleText or maybe the whole "innersection" div if that is easier. Also trying to horizontally align the TitleText within the remaining space left after the image has been aligned to the left.
<html>
<head>
<style>*{margin: 0; padding: 0;}</style>
</head>
<body>
<div id="header" style="position: absolute; top: 0px; height: 8em; width: 100%; background: grey;">
<div id="titlesection" style="height: 6em; background: green;">
<div id="innersection" style="margin-top: auto; margin-bottom: auto; background: yellow;">
<iimg src="images/burgee.jpg" style="vertical-align: center;">
<span style="width: 100%; margin:0 auto; text-align: center; font-size: xx-large; background: teal;">TitleText</span>
</div>
</div>
<div id="menu" style="position: absolute; bottom : 0px; height: 2em; width: 100%; background: lightblue;">
menu goes here
</div>
</div>
</body>
</html>
Almost there. I couldn't just give up and use a table instead, would have been too easy.
Currently have the code below which partly works but... When I use a div for the TitleText it centers horizontally but is not exactly vertically inline with the image. Change to a span instead (without float: left) and vertical alignment is correct, just that then because a span doesn't span the whole width of the header the text is no longer centered.
So near but so far! Can anyone see how to get this working.
Thanks,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<style>
.VCentOuter {
top: 0; left: 0; width: 100%; height: 100%; position: absolute; display: table
}
.VCentInner {
display: table-cell; vertical-align: middle
}
#header{
height: 17em;
width: 100%;
}
#header img {
margin: 1em;
}
#title{
width: 100%;
text-align: center;
color: Red;
font: bold italic xx-large "Century Gothic", "sans-serif";
}
</style>
</head>
<body>
<div id="header">
<div class="VCentOuter" style="height: 15em; background: green;">
<div class="VCentInner" style="background: blue;">
<img src="images/burgee.jpg" style="vertical-align: middle; float: left;"/>
<div id="title" style="width: 100%; background: pink;">TitleText</div>
<!--
<img src="images/burgee.jpg" style="vertical-align: middle"/>
<span id="title" style="width: 100%; background: pink;">TitleText</span>
-->
</div>
</div>
</div>
</body>
</html>