Forum Moderators: not2easy
But it only works in Explorer, and not even Opera.
<style> </HEAD> <div id="container"> </BODY>
<HTML>
<HEAD>
#container {width:100%;text-align:center}
#pageitself {width:580px;text-align:left}
</style>
<BODY>
<div id="pageitself">This is the page we want to be centered.</div>
</div>
</HTML>
The old, deprecated <CENTER> tag was simple and elegant for this kind of functioning. In Opera and Netscape 6 th e <center> tag will still center a div on the page, even though it's now deprecated. But not in Netscape 4.x! No method I can find will center an entire div in Netscape 4.x.
My guess is that tables are still required to get this centering effect with the current browser situation. I'd sure love to hear differently.
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--
if (window.innerWidth) {
var maxwid = 750
var wid = (window.innerWidth - 32)
var marg = (((wid-maxwid)/2)-(((wid-maxwid)%2)/2));
if (marg>0) {
document.write('<STYLE TYPE="text/css">\n');
document.write('.main \{\n');
document.write('margin-left: ');
document.write(marg);
document.write('px;\nmargin-right: ');
document.write(marg);
document.write('px;\n\}');
document.write('<');
document.write('/STYLE>')
}
}
// --></SCRIPT>
It has it's limitations, namely the browser must support JS with the innerWidth object as well have support for margin-left and margin-right CSS. And the margins remain when the window is resized. But maybe this will give someone some ideas and inspire them to make an improved version of it.
One thing that should work for every CSS compliant browser:
margin-left: auto;
margin-right: auto;
width: 80%;
But it seems only the Opera designers fully read the CSS spec ;)
In IE, you'll have to do something like:
<div style='text-align: center; width: 80%;'>
<div style='text-align: left;'>
<!-- text here is left justified and centered with 10% margins each side -->
</div>
</div>
Hope that helps.
Alex
<table width="100%" height="100%">
<tr>
<td align="center" valign="middle">
Your page goes in another table here....
<td>
</tr>
</table>
there are also a number of rendering problems associated with pages entirely created within a table
Try getting a div box in the top left (say a logo), and another div filling the rest of the top right. Tables do that nicely, but this is a whole new ball game!
Floating div's bother me too... in most browsers, the floating divs can overflow their parent's boundaries. Anyway, i'm rambling now.