homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque & physics

Webmaster General Forum

Center and Left Justify Web Pages Depending Upon the Window Width
Centering depending upon the window width.

 3:39 pm on Jan 15, 2009 (gmt 0)

How do you center a web page when the browser window is wider than the web page and left justify the web page when the browser window is narrower than the web page? I want to apply this to all web pages. yahoo.com is one such example. I'm using Dreamweaver CS4.



 3:02 pm on Jan 19, 2009 (gmt 0)

You need to have a container element. We will say a div that contains all the elements you want centered. You may already have this element. Add this style to it:

margin: 0 auto;

You also need to add

text-align: center;

That is for older browsers like IE 6 I believe.

Corey Bryant

 9:11 pm on Jan 19, 2009 (gmt 0)

Hopefully you are also relying on an external sheet to help you maintain the consistency of the layout as well.

Here is another example
margin:0px auto;
padding: 0px;
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 1.0em;
text-align: left;
background: #fff;
color: #000;
width: 921px;
margin: 0px auto;
text-align: center;
text-align: left;

And then in your HTML code, something like
<div id="wrapper">
<div id="maincontainer">Lorem Ipsum


 11:48 pm on Jan 19, 2009 (gmt 0)

Thanks for the feedback, worked like a charm.

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved