Solved

center table vertically **URGENT 500 POINTS**

Posted on 2006-06-12
7
275 Views
Last Modified: 2012-05-05
I have a table that should be centered vertically but it always shows up right below my top table. How can I fix it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The Specialists Pricetag Generator</title>
<link href="/css/stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
            <td valign="top">
                  <table width="100%" height="10px" border="0" cellpadding="8" cellspacing="0">
                        <tr>
                              <td bgcolor="#003A69" class="menu"><div align="left">Test1</div></td>
                              <td bgcolor="#003A69" class="menu"><div align="center">Test2</div></td>
                              <td bgcolor="#003A69" class="menu"><div align="right">Test3</div></td>
                        </tr>
                  </table>
            </td>
      </tr>
      <tr>
            <td align="center" valign="middle" height="100%">
                  <form action="/?action=tagSheet" method="post" name="choose_tag_type">
                        <table width="400px" border="1px" bordercolor="#CCCCCC" cellpadding="0" cellspacing="0">
                              <tr>
                                    <td height="30px" colspan="2">
                                          The Specialists Pricetag Generator
                                    </td>
                              </tr>
                              <tr>
                                    <td align="left">Tag Type:</td>
                                    <td align="left">
                                          <select name="tag_type" onchange="choose_tag_type.submit()">
                                                <option value="">--------------------</option>
                                                <option value="1">Normal Tag</option>
                                                <option value="2">Head Unit Tag</option>
                                          </select>
                                    </td>
                              </tr>
                        </table>
                  </form>
            </td>
      </tr>
</table>
</body>
</html>


Max
0
Comment
Question by:TheMaximumWeasel
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
bowen18 earned 500 total points
ID: 16888959
Your <DOCTYPE> tag is keeping it from working, as the way you've used relative height is invalid for xhtml.

Remove the following line:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

And change this line:
<html xmlns="http://www.w3.org/1999/xhtml">

to:
<html>

This page has a pretty good explanation of what's going on:
http://www.apptools.com/examples/tableheight.php
0
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16889181
Thanks

Max
0
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16889190
I knew it was invalid XHTML but I didn't realized that the browser ignores invalid stuff because it used to work then I would apply height with CSS.

Max
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16889644
>  Remove the following line:
>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

What???  Your page MUST have a docytpe!!!

The dirty trick is to use this CSS (as in the link posted by bowen18):

   html,body{
      height:100%;
   }

But the only 100% correct solution is not to use any vertical centering...  and use some margin/padding instead.
0
 
LVL 2

Expert Comment

by:bowen18
ID: 16890175
> What???  Your page MUST have a docytpe!!!

A bit dramatic, eh?  To be valid and proper, yes, the page should have a doctype.  However, in this example, the page will display properly without it.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16890350
> A bit dramatic, eh?
Yes, a dramatic response to a dramatic advice :)
You gave the link to an article that explains the issue.
That's because relative heights are treated as "auto" when the container does not have an explicit height and that its "position" is not "absolute".
Using the "html,body{ height:100%; }" trick is not ideal, but it's much better than using quirks mode + invalid code.
0
 
LVL 4

Author Comment

by:TheMaximumWeasel
ID: 16915018
css didn't work either I just decided to not center it vertically.

Max
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now