Issue
How can I adapt the CSS selector below:
.myTableRow td:nth-child(?){
background-color: #FFFFCC;
}
so it applies to td
columns 2
~4
?
<table>
<tr class="myTableRow">
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
<td>column 5</td>
</tr>
</table>
Solution
You won't be able to do this with a single :nth-child()
— you'll need to chain at least one other such pseudo-class. For example, a combination of :nth-child()
and :nth-last-child()
(the n+2
bit means start counting forward and backward respectively from the 2nd child):
.myTableRow td:nth-child(n+2):nth-last-child(n+2){
background-color: #FFFFCC;
}
Alternatively, instead of making use of a formula, simply exclude :first-child
and :last-child
:
.myTableRow td:not(:first-child):not(:last-child){
background-color: #FFFFCC;
}
Answered By - BoltClock
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.