CSS 如何在 detailsview 数据行中选择第二个 td?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/901273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:37:19  来源:igfitidea点击:

How to select second td in detailsview datarow?

cssdetailsview

提问by uzay95

I am trying create a new css for shaping my detailsview. But i couldn't reach to second td in detailsviews field rows. do you have any idea to access 2nd td?

我正在尝试创建一个新的 css 来塑造我的详细信息视图。但是我无法在 detailsviews 字段行中到达第二个 td。你有什么想法可以访问第二个 td 吗?

But please imagine belov code generated by detailsview.

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

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

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


回答by cletus

The first question is: do you need to support IE6? If the answer is yes then you can't do it. If not the easiest solution is probably:

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

td + td { ... }

Even more modern (and less supported) is:

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

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

This presupposes that you're not willing or not able to put a class or other identifier on the second td so you can do it much more easily.

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

回答by flitzwald

I'd recommend against selecting a field that happens to be the second in a row. A better approach would be to assign meaningful css classes to the fields and selecting those:

我建议不要选择恰好是连续第二个的字段。更好的方法是为字段分配有意义的 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>