Forum Moderators: phranque

Message Too Old, No Replies

Center in all browsers.

How to display the page in the center of the browser?

         

engasi

1:45 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



Hi Guys,

I have a general question. I want to make sure all my pages displaying in the center position of browser, no matter what kind of browser, what the size of the openning browser or what resolution the monitor setting.

I think it can be done in the HTML code. But I am not sure how to do it. Any suggestion is highly appreciated.

chris_f

1:50 pm on Jun 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<center> or <div align=center> will do the trick.

Chris

p.s. A search engine can tell you all you need if you search for "html tutorial".

tbear

4:44 pm on Jun 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



And don't forget to close it afterwards........
</center> or </div>

broniusm

8:38 pm on Jun 27, 2003 (gmt 0)

10+ Year Member



dang- I was waiting for the real answer on this one, too. My guess is engasi's not asking the obvious, but trying to figure out how to do absolute center (horizontally and vertically centered) on a page:

<style>
table { height:100%; width:100%; }
tr.valign { vertical-align:center; }
tr.valign td { text-align:center; }
</style>

<table>
<tr class="valign">
<td>absolutely centered</td>
</tr>
</table>

grahamstewart

8:12 am on Jun 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want your HTML to validate (and you should) then you can't use <center> or <div align="center"> - they are both deprecated.

The 'correct' way to center a div is to specify 'auto' for its left and right margins.


div#centered {
margin: 0 auto;
}

Older browsers will also center divs if you specify
text-align: center
on the parent element.

engasi

4:12 pm on Jul 7, 2003 (gmt 0)

10+ Year Member



Thanks for you guy's help. What I mean is the horizontally center. Take a look at [google.com....] No matter what browser you are using, the homepage of Google always displays in the center. Can anybody let me know how to do this? Thanks.

BlobFisk

4:16 pm on Jul 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using CSS you can center a <div>, which acts as the container for all your content, as grahamstewart has outlined. In this case, you parent element is the body.