If I have couple <div>s within a <td>, can I select each one?
For example i want to make the first one float left and the second float right. is it possible using just CSS?
.divE:first-child { float:left; }
.divE:last-child { float:right; }
HTML
<table id="myTbl" cellpadding="0" cellspacing="0">
<tr>
<td>
<div class="red">asdasd</div>
<div class="divE"></div>
<div class="divE"></div>
content
</td>
</tr>
</table>
Yes it is 🙂
You can set the .divE class to float left by default, and then you can by using the adjacent sibling selector define, that when an div of the divE class immediately follows another div of the divE class, it should float right like this:
But isn’t it easier just to give the divs an id each, and then set the floats to each? Or just apply a .floatRight or .floatLeft class to the divs, and then change the floats of these classes? In this way you could reuse the classes.
If you changed your HTML to:
And add CSS like this: