Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make :after element only if there is another element after it

Tags:

html

css

I want to have after elements only if there are other elements after it. Here is my code so far:

<table id='table_1'>
   <tr>
    <td>A</td>
    <td>B</td>
    <td>C</td>
 </tr> 
</table>

Is it possible to have :after after A and B, but not C?

My CSS

#table_1 td:after{
content: "";
background: black;
border: 1px solid black;
position: relative;
margin-left: 10px;
}
like image 314
Alex M. Avatar asked Feb 11 '23 05:02

Alex M.


1 Answers

Easiest way to do it is to use the not(:last-child):

#table_1 td:not(:last-child):after{
    content: "";
    background: black;
    border: 1px solid black;
    position: relative;
    margin-left: 10px;
}

Working exmaple

That way you have only one selector and you don't need to override your code.

like image 56
Or Duan Avatar answered Feb 14 '23 00:02

Or Duan