Forum Moderators: open
<BODY BGCOLOR=#000000 leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
to place my page in the topmost left corner of the browser... I'm trying to figure out how to write a BODY tag to put the page in the topmost center part of browser. Can you do it with a body tag, or do you need a CSS?
.top {position: absolute; top: 0px; left: 0px } Then, put all of your page content inside:
<body>
<table class="top" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td align="center">
[b]page content here[/b]
</td></tr>
</table>
</body> That should create an invisible top-flush table with everything inside it centered.
(edited by: mivox at 5:46 pm (utc) on May 23, 2002)
[color="blue"]<html>
<head>
<title>Untitled</title>
<style type="text/css">
body {
margin: 0px 10% 0px 10%;
background: #FFF;
}
</style>
</head><body marginwidth="0" marginheight="0">
<p>Sample text. Put yer content here.</p>
</body>
</html>[/color]
You can adjust the left and right margins (the 10% values above; margin is read clockwise, from top) as you see fit.
If you want the content centered, just add "text-align: center" to the body css.
The
marginheight and marginwidth attributes on the body element are to get NS4 and Opera to behave. Not standards compliant, though. ...
nitpicky, but why not?But you don't mind using deprecated HTML attributes? ;)
Seriously, I can see your point. Those particular attributes are vendor extensions to html. However, I am nitpicky too, and try to avoid using tables for layout as much as possible. Six one way, half dozen the other I guess.
Also, text-align wouldn't apply to *everything* in the body content[...]
True, true. You could always use
<div align="center"></div> to contain the content though, or cascade text-align through all of those elements you wanted centered. Still, my impression was not that the original poster wanted all his/her content to be centered, just the container that held the content (a popular design nowadays).
(Perhaps newnewbie will return and clarify his wishes for us, so we can resume bickering with more focus? ;) )
I spent a couple of days pulling my hair out over a centered, padded div layout on my personal site, trying to get everything lined up properly in everything including NN4... finally got it to work without a <table> to be found on the page, and no <font>s or align="centered"s either. Nice little "floating" box full of text in the middle of the page! I wouldn't recommend it to anyone with a potential blood pressure problem though. hehe
First, I agree with you in essence, but I think centering on the screen is one of the real pitfalls of CSS - a major oversight in my opinion. You asked "why not" use % margins. Well, the reason is simple: if you have a fixed-width element (e.g. a logo) this will *not* be centered. Its left edge will be x% of the viewable area (VA) from the left edge of the screen. If you have
VA: 1000px
margins 10%
logo 100 px
You will have
left-side whitespace: 100px
logo: 100px
right-side whitespace: 800px.
It only comes out centered if you have enough fluid inline material (e.g. lots of text) to fill the box from margin to margin. You can do tricks with "text-align" like making sure your image is within a paragraph that is text-aligned center, but this won't help with block-level elements.
I don't see why CSS won't let you just declare that a div be centered.
Tom
It only comes out centered if you have enough fluid inline material (e.g. lots of text) to fill the box from margin to margin. You can do tricks with "text-align" like making sure your image is within a paragraph that is text-aligned center, but this won't help with block-level elements.
Maybe I am just being dense, but I'm not sure I see the problem.
If you want the image centered, put it in a container div with align="centered" (or text-align: centered). This is perfectly legal and philosophically sound, since div is a generic block-level element meant for styling uses. Or maybe it is the practice of using container divs that you object to?
I don't see why CSS won't let you just declare that a div be centered.
I think it was for the same reason that the W3C version of "width" doesn't include borders, padding, and margins -- to obfuscate things. ;)
align="centered" (or text-align: centered). This is perfectly legal and philosophically sound,
Just to be pedantic ;) The CSS version is of course. The "align" version depends on what legal standard you want to apply since "align" is deprecated since HTML 4.01
"width" doesn't include borders, padding, and margins -- to obfuscate things.
This is just a matter of perspective isn't it? You may think it's more logical that width defines the space that a box takes up, but the you may find it more logical to define width in terms of how much the box can hold. This is a matter of preference and perspective, not obfuscation.
Tom