Html Table alignment right
You had some incorrect syntax. You were using style="align-right"
when I believe you meant style="text-align:right;"
. You also need to add a colspan="2"
to the <td>
which needs to span 2 columns - aka the "item b" cell:
<table width="500px">
<tr>
<td>
item a
</td>
<td style="text-align:right;" colspan="2">
item b
</td>
</tr>
<tr>
<td>
item c
</td>
<td style="text-align:right;">
item d
</td>
<td style="text-align:right;">
item e
</td>
</tr>
</table>
xdumaine
Xander Dumaine I believe in inclusion, equality, and communication. I like solving technical problems to help further those principles. I'm currently enthusiastically working in React, GraphQL, DynamoDB, AWS Lambda, and Apollo. My CV is available at http://careers.stackoverflow.com/dumaine I'm also a rock climber, cyclist, and husband. I blog at http://blog.xdumaine.com and some other stuff is at http://www.xdumaine.com
Updated on June 13, 2022Comments
-
xdumaine almost 2 years
-------------------------------- | item a item b | | item c item d item e | --------------------------------- | item a item b | | item c item d item e |
I have two rows in a table, and I'd like them to each have a left aligned item, and some right aligned items, like in the first example above.
However, when I set
item b
,item d
, anditem e
toalign="right"
, I get the behavior of the second example above. Why isitem b
lining up withitem d
and notright
?Edit: Jsfiddle
-
emboss over 12 years+1 Yes, the colspan solution is even better, saving some text there.
-
xdumaine over 12 yearsHa! Thanks, I did have that syntax error in my jsfiddle. I just put that together quickly for the question, and didn't have that error in my original code. I was trying to use the td property
align
and not style. so, instead ofstyle="text-align:right"
, I originally hadalign="right"
but it was the colspan that did the trick, in either case.