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.
I have this table for
I'm looking for a way with less as possible css.. preferred HTML only.
You can try align
attribute of td
with colspan
.
<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" align="right">right</td>
</tr>
</table>
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>
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>
<tr>
<td colspan="2">this</td>
<td align="right">right</td>
</tr>
colspan can be used in both cells. This will merge cell into 2.
you can only add align="right"
attribute
<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" align="right">right</td>
</tr>
</table>
Or just insert an empty cell before <td>this</td>
<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></td>
<td>this</td>
<td>right</td>
</tr>
</table>