在表tr中使用nth-child [英] using nth-child in tables tr td

查看:158
本文介绍了在表tr中使用nth-child的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < table> 
< tr>
< th>& nbsp;< / th>
< td> $< / td>
< td>& nbsp;< / td>
< / tr>
< tr>
< th>& nbsp;< / th>
< td> $< / td>
< td>& nbsp;< / td>
< / tr>
< tr>
< th>& nbsp;< / th>
< td> $< / td>
< td>& nbsp;< / td>
< / tr>
< tr>
< th>& nbsp;< / th>
< td> $< / td>
< td>& nbsp;< / td>
< / tr>
< tr>
< th>& nbsp;< / th>
< td> $< / td>
< td>& nbsp;< / td>
< / tr>
< / table>

这是我的代码,我想要< td> < tr> 中具有背景为 #CCC 的$ / p>

任何人都可以使用 nth-child ,伪类帮助我如何做?

解决方案

  table tr td:nth-​​child(2){
background:#ccc;
}

工作范例: http://jsfiddle.net/gqr3J/


<table>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>$</td>
    <td>&nbsp;</td>
  </tr>
</table>

Here is my code, I want <td>s with "$" with a background of #CCC in all the <tr>s.

Can any one help me how to do this using nth-child, pseudo classes?

解决方案

table tr td:nth-child(2) {
    background: #ccc;
}

Working example: http://jsfiddle.net/gqr3J/

这篇关于在表tr中使用nth-child的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆