Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

XHTML Help: Tables!

killerTwinkiekillerTwinkie Member CommonPosts: 1,694

Hey Everyone,

Im creating a table and need to align the table itself to the center; however, when I do this it is also aligning the table data into the center as well. It shouldnt be aligning to the center, it needs to be aligned left.

Anyone know a way to fix this with XHTML? I could use CSS...but i'm not allowed for this example.

 

Here is the code:

<?xml version="1.0" encoding="UTF-8"?>

<!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>

<title>TV list by Matthew Goodard </title>

</head>



<body>

<div align="center">

<h3>WMTZ</h3>

<h2>Channel 17, Atlanta</h2>

<h5>Schedule: 6/6/05 - 6/12/05</h5>

</div>



<hr />

<table align="center" border="4" cellspacing="5" width="75%">

<tr>

<th bgcolor="yellow"> Day </th>

<th bgcolor="yellow"> 7:00 </th>

<th bgcolor="yellow"> 7:30 </th>

<th bgcolor="yellow"> 8:00 </th>

<th bgcolor="yellow"> 8:30 </th>

<th bgcolor="yellow"> 9:00 </th>

<th bgcolor="yellow"> 9:30 </th>

</tr>

<tr>

<td bgcolor="yellow"> Mon. </td>

<th> The Nanny </td>

<th> Fred's Place </td>

<th> Old Friends </td>

<th> Cybill </td>

<th colspan="2"> Emergency Center </td>

</tr>

<tr>

<td bgcolor="yellow"> Tue. </td>

<th colspan="2"> Babylon 5 </td>

<th> Tonite! </td>

<th> 911 Stories </td>

<th colspan="2"> Mission Impossible </td>

</tr>

<tr>

<td bgcolor="yellow"> Wed. </td>

<th colspan="2"> Special: The Budget Crisis </td>

<th colspan="2"> Perfume </td>

<th colspan="2"> 48 Hours </td>

</tr>

<tr>

<td bgcolor="yellow"> Thu. </td>

<th> Mel's Diner </td>

<th> Alien World </td>

<th colspan="4"> Movie: Wayne's World III </td>

</tr>

<tr>

<td bgcolor="yellow"> Fri. </td>

<th colspan="6"> Movie Special: Schindler's List </td>

</tr>

<tr>

<td bgcolor="yellow"> Sat. </td>

<th rowspan="2" colspan="2"> Dr. Quinn </td>

<th colspan="2"> Murder for Hire </td>

<th colspan="2"> New York Streets </td>

</tr>

<tr>

<td bgcolor="yellow"> Sun. </td>

<th> Wild Life </td>

<th colspan="3"> Movie: The Lost World </td>

</tr>

</table>



<hr />

<div align="center">

<h5> Favorite television viewing links: </h5>

<a href="http://www.abc.com">ABC| </a>

<a href="http://www.cbs.com">CBS| </a>

<a href="http://www.nbc.com">NBC </a>

</div>

</body>

</html>

KillerTwinkie - That one guy who used to mod mmorpg.com's forums.

Comments

  • killerTwinkiekillerTwinkie Member CommonPosts: 1,694

    Nevermind... I am retarded.

    <th align="left"

    Wow. :(

    KillerTwinkie - That one guy who used to mod mmorpg.com's forums.

  • sephersepher Member Posts: 3,561

    Yeah you can text align otherwise in the table hierarchy.

    FYI you're closing TH tags with TD tags. TH should be used only for headers only. You should think about structuring the whole thing correctly as: 

    <table>

       <caption></caption>

       <thead>

          <tr>

             <th></th>

          </tr>

       </thead>

        <tfoot>

          <tr>

             <td></td>

          </tr>

       </tfoot>

       <tbody>

          <tr>

             <td></td>

          </tr>

       </tbody>

    </table>

     

    ...which would be typical. That way you can throw your align for the entire table in the table tag, then align your header, footer, body similarly with align. Or if you have to, drill down to the individual rows and cells with align tags.

    Not sure why you can't use CSS but the align attribute has been deprecated a long time, its not guaranteed to work in every browser as you'd expect it to, but that's how you'd structure your table better.

  • killerTwinkiekillerTwinkie Member CommonPosts: 1,694

    Thanks for the response.  While you're absolutely correct with the th and td, I had to build it to fit specification for my xhtml/css class. They didnt have the caption to portray what it was used for and she wanted the data to be bold.  I had to find a work around without using the CSS.

    I also forgot the th tags weren't closed correctly. Went to validate it and saw 77 errors =) Imagine my surprise!

    KillerTwinkie - That one guy who used to mod mmorpg.com's forums.

Sign In or Register to comment.