English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
:last-of-type CSS pseudo-class represents the last element of the given type in the list of child elements (of its parent element). When the code is similar to Parent tagName:last-of-The scope of type includes the last selected element among all child elements of the parent element, including the last child element of the child elements, and so on.
Complete CSS Selector Reference Manual
Specify the background color of the last p element of its parent element:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> <style> p em:last-of-type { color: green; } </<style> </<head> <body> <p> <em>I don't have color :(</em><br> <strong>I don't have color :(</strong><br> <em>I have color :D</em><br> <strong>I don't have color :(</strong><br> </p> <p> <em>I don't have color :(</em><br> <span><em>I have color!<!/em></span><br> <strong>I don't have color :(</strong><br> <em>I have color :D</em><br> <span> <em>I am in a child element, but I don't have color!<!/em><br> <span style="text-decoration:line-through;"> I don't have color </span><br> <em>I do have color!<!/em><br> </span><br> <strong>I don't have color :(</strong> </p> </body> </html>Test to see ‹/›
element:last-of-type { style properties }
:last-of-The type selector matches the last child element of a specific type in its parent element.
Hint: and :nth-last-of-type(1) means the same thing.
The numbers in the table indicate the first browser version that supports this attribute.
Selector | |||||
---|---|---|---|---|---|
:last-of-type | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |