Reputation: 1779
I have a table. Inside the td's I have two span tags - the one span tag i want to align left, and the other right, but the td does not allow that:
<table>
<tr>
<td colspan="5"><span>$</span><span>1000</span></td>
</tr>
</table>
So I want the $ to be aligned to the far left of the td and the 1000 to align to the far right of the td.
Is that possible?
Upvotes: 14
Views: 27355
Reputation: 4025
You can use the following selector, without using extra classes:
td span:last-child{ /*not compatible with <=IE8*/
color:green;
float:right;
}
Demo: http://jsfiddle.net/QR3kP/1/
For compatibility with IE7 and up use the CSS code below:
td span{
float:right;
}
td span:first-child{ /* compatible to >=IE7 */
float:left;
}
Demo: http://jsfiddle.net/QR3kP/4/
Another approach is to right align the text inside the <td>
and float
only the first <span>
:
td {
text-align:right
}
td span:first-child {
float:left;
}
Demo: http://jsfiddle.net/QR3kP/29/
You can use a similar method with the above by using even less css declarations:
td span:first-child + span {
float:right;
}
In the example above, the default td
text align is left and you only select the sibling which is immediately preceded after the first span
. Then you just float
it to the right. Of course, you may use the ~
selector, which is the same thing in this case.
Demo: http://jsfiddle.net/QR3kP/32/
See the compatibility chart here: http://kimblim.dk/css-tests/selectors/
See the CSS selectors here: http://www.w3.org/TR/CSS2/selector.html
Upvotes: 20
Reputation: 1880
The best way would be to place a class onto each of the spans and apply the float to each ot the classes
HTML
<span class="left">$</span><span class="right">1000</span>
CSS
.left{float:left;}
.right{float:right;}
Upvotes: 3
Reputation: 51624
You can define the float
style for the spans using CSS classes.
<style>
.left { float: left; }
.right { float: right; }
</style>
<table>
<tr>
<td colspan="5">
<span class="left">$</span>
<span class="right">1000</span>
</td>
</tr>
</table>
Upvotes: 1
Reputation: 7952
You can set float: left
on the span
containing $
, and float: right
on the span
containing your dollar amount.
Here's a simple demo of it.
Upvotes: 3
Reputation: 35963
Try this:
<table style="width:100%">
<tr>
<td colspan="5"><span style="float:left;">$</span><span style="float:right;">1000</span></td>
</tr>
</table>
Upvotes: 2
Reputation: 19740
Probably best off doing it with floats.
<td colspan="5"><span class="left">$</span><span class="right">1000</span></td>
CSS:
.left {
float: left
}
.right {
float: right;
}
jsFiddle: http://jsfiddle.net/NLZU5/
Upvotes: 3
Reputation: 92274
Simplest way is to float the first one to the left and the second one to the right
<table width="100%">
<tr>
<td colspan="5">
<span style="float:left">$</span>
<span style="float:right">1000</span></td>
</tr>
</table>
Upvotes: 1