Center a DIV

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Center a DIV

Post by phppage »

Would anyone know how I could horizontally center a DIV section in the middle of a page. The DIV needs to be fixed at 800 pixels wide but of course the page width may vary from different resolution settings on the users machine.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Set the left and right margins to 'auto'.
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Post by phppage »

Oren wrote:Set the left and right margins to 'auto'.
Thanks for your quick reply. Tried that but found that it doesn't work in IE. Found the solution.

http://www.andybudd.com/archives/2004/0 ... /index.php
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Yeah, that's exactly what I meant. I just forget to mention to tell you to put in the body text-align: center; :P Sorry about that.
This is exactly the way I always use.
Post Reply