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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on echo of HTML not right aligning?

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
Can someone explaing to me why the following script does not right align the headings? Thanks for suggestions.

<?
echo '<table width="640" cellspacing="5">';
echo "<tr>";
echo '<td width="20" align="right"><strong><font size="2" face="Arial, Helvetica, sans-serif">TYPE</stong></font></td>';
echo '<td width="10" align="right"><strong><font size="2" face="Arial, Helvetica, sans-serif">HOURS</stong></font></td>';
echo '<td width="10" align="right"><strong><font size="2" face="Arial, Helvetica, sans-serif">RATE</stong></font></td>';
echo '<td width="10" align="right"><strong><font size="2" face="Arial, Helvetica, sans-serif">TOTAL</stong></font></td></tr></table>';
?>
 
it works fine for me...unless the table property is getting set some other way...this should work fine. btw i also added a border="1" in the <table width="640" cellspacing="5">
ko12
 
right... the problem is your width declaration in the table cells:

<td width = "20" align = right>

width = "20" needs to be width = 20px or % or whatever

The reason kaancho12 got it to work i think (and i'm just guessing here) is that he/she's using firefox as a browser which is much more versatile when it comes to web standards so it just ignores the invalid width = "20" and aligns the text right anyway.

Whereas IE which you are probably using obviously spazzes out when it sees the width value and then ignores the align.

hope this helps
 
Absolutely... I changed it to 20% and it works fine now. I am using IE so it is choking on the '20'.

Thanks
 
Simply to put a hold at the incorrect teachings here. The width="20" means that width equals 20px, width="20%" means it is at 20% and width="20px" is incorrect syntax. The choking part was probably the column width being to little to do any aligning at all, whence changed to percentage, the width grew to accomodate aligning.

Also, I have no idea what is meant by firefox's versatility when it comes to interpreting standards. I would say FF is much stricter when it comes to interpreting standards and will choke much sooner on the code than IE would. IE interprets the standards more loosely and that is why pages that are coded wrongly look good on IE but not on FF.

Table cells will expand to fit the non-breaking content. If you instruct the width of a cell to be 20px (width="20"), but actual text is say 30px wide, cell be 30px wide but none of the aligning will be visible, since the cell had to be expanded to fit the content anyway.
 
Thanks for the referrence. Good stuff!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top