HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Centering a fixed-width container div in broswer window.
Post new topic   Reply to topic    HTML Help Forum Index -> CSS
View previous topic :: View next topic  
Author Message
building_my_own_site



Joined: 19 Jan 2008
Posts: 7

PostPosted: Thu May 22, 2008 12:20 pm     Centering a fixed-width container div in broswer window. Reply with quote

I have a container div that is set to have a fixed width, and I would like this centered in the middle of the browser window.

I have been looking into using the "position: absolute" attribute of css. However, it appears to me that this will only allow me to set a fixed left/right/top/bottom position either in pixels (etc,etc) or percentage - with different sizes of browser windows , this would mean that the position would not be in the center.

I know there must be a way to do this as I have seen other sites like this, but looking at the attribute in IE Developer Toolbar, I cannot figure out how to do this.

Any help would be appreciated.

Many Thanks.
Straystudio



Joined: 14 Apr 2008
Posts: 255
Location: Nord Italy

PostPosted: Thu May 22, 2008 12:50 pm     Reply with quote

ANCIENT SOLUTION (the best), a bare DIV upper container:

<div align="center">
      Your fixed-width div container here
</div>
sticks464



Joined: 31 Dec 2006
Posts: 1100

PostPosted: Thu May 22, 2008 3:22 pm     Reply with quote

You can do it with the deprecated 'align="center' or you can use css

<div style="margin:0 auto">
content here
</div>
building_my_own_site



Joined: 19 Jan 2008
Posts: 7

PostPosted: Sun May 25, 2008 1:21 am     Reply with quote

Thanks guys.

There is always an easy way to do things!


One point that I have noticed for people attempting the same thing:

The "margin: 0px, auto" in css didn't seem to work in I.E.until i specified the document type in my html page.

I read up about this, and it is very useful as it forces browsers to interpret XHTML code as opposed to HTML - they are both very similar but XHTML just requires syntacticlly correct code. (w3schools for the tutorial if you need one!)
building_my_own_site



Joined: 19 Jan 2008
Posts: 7

PostPosted: Sun May 25, 2008 1:24 am     Reply with quote

Forgot to mention the DTD:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> CSS All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial