How to select second td in detailsview datarow?
-
05-09-2019 - |
Question
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?
But please imagine belov code generated by detailsview.
<table>
<thead>
...
</thead>
<tbody>
<tr>
<td>Name</td>
<td><input type='text' id='txtName' /></td>
</tr>
</tbody>
</table>
Solution
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:
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.
OTHER TIPS
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:
<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow