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

Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

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

5+ Year Member



 
Msg#: 3827154 posted 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.

 

korkus2000

WebmasterWorld Senior Member korkus2000 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3827154 posted 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

body
{
text-align: center;
}

That is for older browsers like IE 6 I believe.

Corey Bryant

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3827154 posted 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
body
{
margin:0px auto;
padding: 0px;
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 1.0em;
text-align: left;
background: #fff;
color: #000;
}
div.wrapper
{
width: 921px;
margin: 0px auto;
text-align: center;
}
div.maincontainer
{
width:960px;
text-align: left;
}

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

CATraveler

5+ Year Member



 
Msg#: 3827154 posted 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