Reputation: 2854
I have two tables with same class
<table class='pp' >
<tr class='pp'>
<td class='pppagetitle'>A Table</td>
</tr>
</table>
<table class='pp' >
<tr class='pp'>
<td class='ppinstance'>Another Table</td>
</tr>
</table>
but want to select only the one with td class pppagetitle (!) - any pointers?
Upvotes: 2
Views: 1772
Reputation: 2854
@Jason Groulx's pointer on a previous post with a very elaborate answer regarding this issue solved things for me:
<style type="text/css">
.pp > .pppagetitle {
border: 1px solid red;
}
</style>
<table class='pp' >
<tr class='pp'>
<td class='pppagetitle'>A Table</td>
</tr>
</table>
<table class='pp' >
<tr class='pp'>
<td class='ppinstance'>Another Table</td>
</tr>
</table>
Upvotes: 0
Reputation: 1291
.pp:nth-child(1){background:green;}
But this isn't well supported (doesn't work in IE8 and below)
Alternatively put the tables in a container and use
:first-child
Example:
<style>
.container > .pp:first-child{background:green;}
</style>
<div class="container">
<table class="pp"></table>
<table class="pp"></table>
</div>
for more documentation: Quirksmode.org
Upvotes: 2
Reputation: 253308
My first thoughts, assuming they share a parent, would be:
table.pp:first-child
But this will, and can, only select the particular table
(with that class) if it's the first-child of its parent element.
There is no :first-of-class()
selector (unfortunately).
Upvotes: 1
Reputation: 6509
You can add another class and select only the table desired:
<table class='pp' >
<tr class='pp'>
<td class='pppagetitle anotherClass'>A Table</td>
</tr>
</table>
<table class='pp' >
<tr class='pp'>
<td class='ppinstance'>Another Table</td>
</tr>
</table>
Upvotes: 0