How to Select the "Last Child" with a Specific Class Name in CSS
When working with CSS selectors, the task of targeting the last child of an element with a specific class can sometimes arise. Consider the following HTML:
<ul> <li class="list">test1</li> <li class="list">test2</li> <li class="list">test3</li> <li>test4</li> </ul>
Our goal is to apply a style to the last child of the
To overcome this issue, we can leverage attribute selectors. Here's how:
[class~='list']:last-of-type { background: #000; }
In this selector:
By combining these selectors, we can effectively style the last child of the specified class. You can find a рабочее, приятное demonstration at http://codepen.io/chasebank/pen/ZYyeab.
For further reference on attribute selectors, check out the following resources:
The above is the detailed content of How to Style the Last Child with a Specific Class Name using CSS?. For more information, please follow other related articles on the PHP Chinese website!