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!

CSS - right align a table 3

Status
Not open for further replies.

cm80

Technical User
May 3, 2001
85
US

Hi,
I am using stylesheets for my web page and I am trying to do the equivalent of <table align=right> but can't find the answer,
can someone help please,
Thanks!
 
Try using the float attribute:
<table style=&quot;float: right&quot;>
...
</table>

-corwin
 
Hi Corwin,
Thanks, that's great! One more thing if you don't mind.... if I want to right/left/center align the text in a table <td> element is it the same syntax?

Thanks again,
cm80
 
Hi cm80,

No, you need to use style=&quot;text-align: <alignment>&quot;

Good luck,

BobbaFet Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
 
Actually that is not the correct way to do it....that is a text align property....it SHOULD not apply to block level elements such as tables.

I know that IE5 will align the table on the right but it does it wrong. A more CSS compliant browser such as Netscape 6.x or Mozilla will not align the table to the right.

The correct way to align a block level element to the right would be to add this CSS to the nested table:

margin-left:auto; margin-right:0px

but of course IE5 coughs all over that. So the solution if you have to have it work in IE5 is to do both, so you would end up with something like this:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;
<html>
<head>
<title>
test
</title>
</head>
<body>
<table width=&quot;500&quot; border=&quot;1&quot;>
<tr>
<td style=&quot;text-align:right&quot;>
<table style=&quot;margin-left:auto; margin-right:0px&quot;>
<tr>
<td>
stuff
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

Hope that helps!
===
Supports Mozilla and Web Standards
Knows HTML/XHTML, CSS1, JavaScript, PHP, C++, DOM1
===
 
He Trevman, your solutions looks OK. (I always vote for new ideas :))
I didn't try it myself, but will do it when I have time.

I'm just curious if you can V-align a table with this trick with using 'margin-top:auto' and 'margin-bottom:auto'

Erik <!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
trevman, the code i gave is correct cm80 asked for text-alignment and that's what it will do.

BobbaFet
BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com

Heineken is like making love in a cano... it's f*cking close to water !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top