Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2012, 05:20 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rookie question: center webpage on screen

Hi,

I usually use tables to format my html page. Question: How do I CENTER my page on the display (with or without tables), I mean, when the width of my webpage is less wide than the total width of the user's display (say, 1280 px vs 1440, or VGA vs. XGA etc.) ?

There should be an align="center" to be put somewhere, but it's scope MUST be the WHOLE page.

Thanks,

Mike
 
Old February 13th, 2012, 05:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can create a <div> with a fixed width and set its margin to auto. E.g.:

Code:
 
<body>
  <div class="PageWrapper">
    Content here
  </div>
</body>
And the CSS:

Code:
 
.PageWrapper
{
  width: 800px;
  margin: auto;
}
margin: auto distributes the available space equally between the left and right side, effectively centering your content on the browser's screen.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 13th, 2012, 05:41 AM
Authorized User
 
Join Date: Nov 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Imar. Not so evident to me !

Mike





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rookie question mitch54 HTML Code Clinic 3 April 7th, 2010 01:18 PM
the rookie is back with a question mitch54 HTML Code Clinic 10 April 5th, 2010 09:23 AM
Small rookie question maximus101 VB Databases Basics 1 February 23rd, 2006 11:51 PM
Rookie question: container div not containing CFGerry BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 6 September 1st, 2005 09:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.