Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS and Alingning Nested Tables 1

Status
Not open for further replies.

AlphaZulu453

Programmer
Jul 29, 2004
9
0
0
US
How can you align nested tables with css, I have been using the text-align statement to do it; it works in Win IE, however it doesn't in Safari.
 
Real aligning in CSS is done by specifying margins to the element you want aligned. Text-align does not work in standards-compliant browsers, because tables etc. are not text, they are block level elements. The text-align property is just used as a hack to accomodate IE's lack of support.
Code:
<table width="100%" border="1">
 <tr>
  <td style="text-align: center;">
   <table width="100px" style="margin: 0 auto;" border="1">
    <tr>
     <td>This table be centered</td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td style="text-align: right;">
   <table width="100px" style="margin: 0 0 0 auto;" border="1">
    <tr>
     <td>This table be aligned to the right</td>
    </tr>
   </table>
  </td>
 </tr>
</table>
Little more explanation. The first margin statement (margin: 0 auto;) is a shortened display. First number relates to top and bottom margins, second to left and right. The second (margin: 0 0 0 auto;) describes the behaviour of all four margins, starting at the top and moving clockwise. That means that top is 0, right is 0, bottom is 0 and left is auto. Hope it is clear.
 
Oops, width should be width="100" not width="100px". I never specify width in html anymore and CSS demands units. Other than that, it is XHTML 1.1 Compliant, so it will fall back to HTML 4.01 Strict as well. The first nested table example is centered. Auto margins on left and right side indicate equal margins to the left and to the right so that the element is centered. And it is for me in Mozilla, Opera and IE.
 
so I can put margin... in my css class, right?
right with my width, etc...
 
Thanks, for the help now everyhting looks alot better :-D.
I'm working to make this site compatible with all "regular" css enabled broswers, unlike the old version wich was only IE compatable.


If you take a look and have any suggestions tell me. Just don't go clicking on liks :p theya re the old version pages and their stayshets were delated as I replaced them with a sheet that made was organized :-D
 
Also while I'm at it what is the CSS code to reblace the good ole:

border="0" cellspacing="0" cellpadding="0"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top