CSS :: To the cell

I want to add a ::before selector to some cells of the table, which has position:absolute , but it does not work:

 table{ border:1px solid #ccc; padding:10px; } table td{ border:1px solid #ccc; padding:5px; } .useBefore::before{ content:'before'; position:absolute; } 
 <table> <tbody> <tr> <td>bird</td> <td>animal</td> <td>nature</td> </tr> <tr class='useBefore'> <td>building</td> <td>robot</td> <td>city</td> </tr> </tbody> </table> 

I noticed that if I add ::before to all tr , then it will work:

 table{ border:1px solid #ccc; padding:10px; } table td{ border:1px solid #ccc; padding:5px; } tr::before{ content:'before'; position:absolute; } 
 <table> <tbody> <tr> <td>bird</td> <td>animal</td> <td>nature</td> </tr> <tr class='useBefore'> <td>building</td> <td>robot</td> <td>city</td> </tr> </tbody> </table> 

But this is not what I want, because I want to add it only to some of them.

+7
source share
1 answer

I am not sure why this is not so, but you can add it to the first cell of the table.

  .useBefore td:first-child:before{ content:'before'; position:absolute; } 
+16
source

All Articles