Nội dung tóm tắt
Cú pháp :last-of-type
(CSS pseudo-class) đại diện cho phần tử cuối cùng trong danh sách các phần tử con có chung phần tử cha trong phép chọn css.
Syntax
:last-of-type
Example
Để chỉ định phần tử cuối cùng bên trong thẻ <p>
, bạn có thể sử dụng cú pháp:
p em:last-of-type {
color: lime;
}
<p>
<em>I'm not lime :(</em>
<strong>I'm not lime :(</strong>
<em>I'm lime :D</em>
<strong>I'm also not lime :(</strong>
</p>
<p>
<em>I'm not lime :(</em>
<span><em>I am lime!</em></span>
<strong>I'm not lime :(</strong>
<em>I'm lime :D</em>
<span><em>I am also lime!</em> <strike> I'm not lime </strike></span>
<strong>I'm also not lime :(</strong>
</p>
...hết quả trả về:
Specifications
Specification | Status | Comment |
---|---|---|
Selectors Level 4 The definition of ':last-of-type' in that specification. |
Working Draft | No change |
Selectors Level 3 The definition of ':last-of-type' in that specification. |
Recommendation | Initial definition |
Trình duyệt (browser) tương thích
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1.0 | (Yes) | 3.5 (1.9.1) | 9.0 | 9.5 | 3.2 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 2.1 | (Yes) | 1.0 (1.9.1) | 9.0 | 10.0 | 3.2 |