Then there's the display:table technique that works in IE8+
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!--
http://www.sitepoint.com/forums/showthread.php?990327-How-to-centre-position-CSS-div
Thread: How to centre position CSS/div
2013.03.02 21:56
ParfaitMacaron
-->
<head>
<title>ParfaitMacaron</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-language" content="en-us">
<style type="text/css">
body {
padding:0;
margin:0;
}
div.header {
display:table;
table-layout:fixed;
width:100%;
}
.header div {
display:table-cell;
background-color:#ffa; /* for demo purposes */
vertical-align:middle;
text-align:center;
}
div + div,
img {
width:250px;
}
img {
height:150px;
display:block;
background-color:#ddd; /* for demo purposes */
}
h1 {
border:5px solid #000;
background-color:#ade;
color:#000;
padding:8px;
margin:0;
}
</style>
</head>
<body>
<div class="header">
<div><h1>Header Text</h1></div>
<div><img src="image.jpg" alt="image"></div>
</div>
</body>
</html>
Bookmarks