CSS3 > Selectors

Last-child selector in CSS3

How to select the Last child of every parent element in CSS3?


By using Last-child selector we can select the first child of every parent element. 

<style>
        b:last-child {
            color: red;
        }
</style>

<body>
    <div>
        <b>This is 'b' element and it is the first child.</b><br />
        <b>This is the 'b' element and it is last child of parent div.</b>
    </div>
    <p>
        <b>This is the first child of the parent 'p' and it is 'b' element.</b><br />
        <b>This is the last child of the parent 'p' and it is also 'b' element.</b>
    </p>
    <br />
    <div>
        <b>This is the first child of the parent div in'b' element.</b><br />
        <b>This is the last child of the parent div in 'b' element.</b>
    </div>
</body>

In the above code snippet we have given last-child selector to the <b> element. So, that it will select the last child in the evary <b> element of its parent element and applies <style> to that particular element. That is shown in the below output.

OUTPUT

 Views: 3698 | Post Order: 27



Write for us






Hosting Recommendations