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 November 28th, 2005, 02:29 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default XHTML & middle aligning web page

I have a website whose content portion is built with tables and is limited to 800 X 600 pixels in width & height. The Doc type used should be XHTML.

I want this page to come at the middle of screen (both horizontally and vertically) in higher resolution. Eventhough I can bring this horizontally at the centre of the screen, I am not able to do it vertically. It is always coming at the top. I can give a fixed margin, but this won't solve the problem. Since I am using XHTML doc type, I cannot specify height and VALIGN attributes.

May anybody tell me a solution ?

thanks

Madhu
 
Old November 28th, 2005, 02:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
Default

For TD you can use 'height' in (X)HTML Transitional. For TABLE you can never use 'height' if you want to validate to any doctype. 'valign' isn't deprecated, I think.

Using CSS you can always set a height for anything. But you'll find that browsers won't vertically center your table when they are in Standards (rendering) Mode. I'm assuming you use the old table-in-table trick here, right? That's because they don't automatically translate height="100%" to "fill the whole veiw-port".

You might find the solution here:
http://www.quirksmode.org/css/100percheight.html


--
http://yupapa.com
 
Old November 28th, 2005, 08:48 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

A table-less solution also exists, and is pretty easy to implement. The following uses layering to vertically center an element.

The document would look something like this
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
    <head>
        <meta http-equiv='content-type' content='text/html; charset=utf-8' />
        <meta http-equiv='content-language' content='en-us' />
        <title></title>
        <style type='text/css'>
             html, body {
                 width: 100%;
                 height: 100%;
                 padding: 0;
                 margin: 0;
             }
             div {
                 background: yellow;
                 width: 500px;
                 height: 500px;
                 border: 1px solid orange;
                 position: absolute;
                 top: 50%;
                 left: 50%;
                 margin: -250px 0 0 -250px;
             }
        </style>
    </head>
    <body>
         <div></div>
    </body>
</html>
The ingredients are simple. Position the layer absolutely, offset by 50% from the top and left, then set the top and left margin to a negative value equal to half of the element's width and height.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old December 2nd, 2005, 02:13 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Thank you Rich and Meow. This technique worked well.

Madhu






Similar Threads
Thread Thread Starter Forum Replies Last Post
Aligning Header & Item DataList Templates rsearing ASP.NET 2.0 Basics 2 October 5th, 2007 06:09 AM
Repeating image in middle of a page ychange Javascript How-To 1 March 11th, 2007 03:45 AM
How to diplay web page inside another web page win cyberjoe C# 2 March 1st, 2007 05:35 AM
XHTML Compliant PHP page Ben Horne Beginning PHP 6 October 27th, 2004 08:08 AM
Rollover prob when Flash inserted in XHTML page socoolbrewster HTML Code Clinic 0 September 12th, 2004 12:54 PM





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