【问题标题】:How to select second td in detailsview datarow?如何在 detailsview 数据行中选择第二个 td?
【发布时间】:2009-05-23 10:30:27
【问题描述】:

我正在尝试创建一个新的 CSS 来塑造我的 detailsview。但我无法达到 detailsviews 字段行中的第二个 td 。你知道访问 2nd td 吗?

但请想象一下 detailsview 生成的 belov 代码。

<table>
<thead>
...
</thead>

<tbody>
    <tr>
        <td>Name</td>
        <td><input type='text' id='txtName' /></td>
    </tr>
</tbody>
</table>

【问题讨论】:

    标签: css detailsview


    【解决方案1】:

    第一个问题是:你需要支持IE6吗?如果答案是肯定的,那么你不能这样做。如果不是最简单的解决方案可能是:

    td + td { ... }
    

    更现代(但支持较少)的是:

    td:nth-child(2) { ... }
    

    这假定您不愿意或不能在第二个 td 上放置类或其他标识符,以便您可以更轻松地做到这一点。

    【讨论】:

    • td+td 选择第2、第3、第4等等。
    【解决方案2】:

    我建议不要选择恰好是连续第二个的字段。更好的方法是将有意义的 css 类分配给字段并选择它们:

    <head>
      <style type="text/css" media="screen">
        td.form-value {
          background-color:red;
        }
      </style>
    </head>
    <tr>
      <td class="form-label">
        Label:
      </td>
      <td class="form-value">
        ...
      </td>
    </tr>
    

    【讨论】:

    • 无法将类名添加到第二个 td。
    猜你喜欢
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多