表格单元格在行内右对齐 [英] Table cells right align inside row
问题描述
我正在尝试弄清楚如何将单元格移到HTML表格的左侧。
我想在最后一行使用较少的单元格,默认情况下它在右侧。
I'm trying to figure out how to move a cell to the left on HTML table. I want to use less cells in the last row and it's on the right by default.
我有此表,例如:
<table>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>this</td>
<td>right</td>
</tr>
</table>
我是试图将 this和 right单元格移到另一侧。
我正在寻找一种使用尽可能少的CSS的方法..仅首选HTML。
I'm trying to move the "this" and "right" cells to the opposite side. I'm looking for a way with less as possible css.. preferred HTML only.
更新:我不是在寻找有关文本/值的答案对齐。 colspan
以某种方式解决了该问题,但仍然不会将其称为完美的解决方案。
Update: I wasn't looking for answers about text/value align. colspan
solves it somehow but still, won't call it a perfect solution.
推荐答案
td
应该使用属性<$跨越两列c $ c> colspan = 2 ,然后将文本向右对齐:
The td
should span two columns by using the attribute colspan="2"
, and align the text to the right:
.alignRight {
text-align: right;
}
<table>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td>this</td>
<td colspan="2" class="alignRight">right</td>
</tr>
</table>
另一个,html唯一的选择是在此单元格上使用 colspan = 2
:
Another, html only, option is to use colspan="2"
on the "this" cell:
<table>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tr>
<td colspan="2">this</td>
<td>right</td>
</tr>
</table>
这篇关于表格单元格在行内右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!