[英]How can I position elements within a table cell (td) such that one element is left aligned and the other right aligned?
[英]How do I create a table with a TD aligned to the left and its sibling aligned to the right?
我想在HTML中創建一個僅包含一行(tr)和兩列(td)的表。
第一個td,我希望其內容與左側對齊,第二個td,我希望其內容與右側對齊。 我該怎么做呢?
tr td{text-align:right}
tr td:first-child{text-align:left}
但是您也可以使用th和td代替2 td。
顯然有幾種方法可以做到這一點,但是在CSS3中,我相信有兩個選項更加具體地針對您的要求。
相鄰兄弟選擇器
td { text-align: left; }
td + td { text-align: right; }
和同級組合
td { text-align: left; }
td ~ td { text-align: right; }
只需在CSS中設置text-align
屬性即可。 默認情況下,第一個不必要,應該保留。
<table style="width:200px;">
<tr>
<td style="text-align: left;">a</td>
<td style="text-align: right;">b</td>
</tr>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.