0
<table>
   <tr><td>aaaaa</td></tr>
   <tr><td>aaaaaaaaaa</td></tr>
   <tr><td>aaa</td></tr> 
</table>

我希望第一行和第三行的文本右对齐而不是第二行,我该怎么做?

4

3 回答 3

2

您可以使用您拥有的 HTML 并使用nth-child选择器

tr:nth-child(odd) {
text-align:right;
}
于 2012-07-24T10:46:51.753 回答
1

Very simple.

 <table>
       <tr style="text-align:right;"><td>aaaaa</td></tr>
       <tr><td>aaaaaaaaaa</td></tr>
       <tr style="text-align:right;><td>aaa</td></tr> 
    </table>

Or use classes:

<table>
           <tr class="tr-right"><td>aaaaa</td></tr>
           <tr><td>aaaaaaaaaa</td></tr>
           <tr class="tr-right"><td>aaa</td></tr> 
        </table>

And add to css:

.tr-right{text-align:right;}

Or as mentioned, you could use the css3 selector, but this doesn't work in all browsers.

tr:nth-child(odd) {
text-align:right;
}
于 2012-07-24T10:44:37.377 回答
0
<table>
    <thead></thead>
    <tbody>
        <tr class='right'><td>aaa</td></tr>
        <tr><td>aaa</td></tr>
        <tr class='right'><td>aaa</td></tr>
    </tbody>
</table>

.rigth{
 text-align:rigth;
}
于 2012-07-24T10:46:52.077 回答