It may or may not be adaptable to what you have in mind, but there's always:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Center</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
html, body {
height: 100%;
margin: 0;
}
#center {
position: absolute;
margin: 0;
top: 50%;
left: 50%;
height: auto;
width: auto;
border: 1px solid #000;
padding: 1ex;
}
</style>
<script type="text/javascript" defer>
(function(){
function center(){
var center = document.getElementById('center');
center.style.marginLeft = center.offsetWidth / -2 + 'px';
center.style.marginTop = center.offsetHeight / -2 + 'px';
}
if (window.addEventListener){
window.addEventListener('DOMContentLoaded', center, false);
}
else if (window.attachEvent){
center();
}
})();
</script>
</head>
<body>
<div id="center">Where Am I?</div>
</body>
</html>
Works in IE 6+, virtually all current version browsers. A word of caution though - if the window is narrower or shorter than the center div, part of it will be off screen to the left or top respectively, with no possibility of scrolling that part into view. And if images are used within the center div, they should have their width and height specified.
Bookmarks