如果我有<div>
s在<td>
之内,我可以选择每个吗?在td中选择div
例如,我想让第一个浮动左边,第二个浮动右边。有可能只使用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>
对于一个特定类的第一个孩子,你可以检查HTTP:// stackoverflow.com/questions/6447045/css3-selector-first-of-type-with-class-name。但是,如果所有表格单元格都包含相似的结构,则可以尝试使用nth-child(n),如下面的答案中所述。 – Adonais