Thí dụChỉ định màu nền cho phần tử là con cuối cùng của cha mẹ: P: Last-Child {& nbsp; Bối cảnh: #FF0000; } background: #ff0000; } Hãy tự mình thử »
Định nghĩa và cách sử dụngBộ chọn :last-child khớp với mọi yếu tố là con cuối cùng của cha mẹ. Mẹo: P: Last-Chill bằng P: Nth-Last-Child (1). p:last-child is equal to
p:nth-last-child(1).
Hỗ trợ trình duyệtCác số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ hoàn toàn bộ chọn.
Bộ chọn | | | | | |
---|
:con cuối cùng | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS Cú pháp : Last-Child {& nbsp; Tuyên bố CSS;} Bản demo css declarations; } Demo
Thí dụChỉ định màu nền cho mọi yếu tố là con thứ hai của cha mẹ, đếm từ đứa trẻ cuối cùng: p: nth-last-child (2) {& nbsp; & nbsp; nền: màu đỏ; } background: red; } Hãy tự mình thử » Thêm ví dụ "hãy thử nó" dưới đây.
Định nghĩa và cách sử dụngBộ chọn :nth-last-child(n) khớp với mọi yếu tố là đứa trẻ thứ n, bất kể loại cha mẹ của nó, đếm từ đứa trẻ cuối cùng. n có thể là một số, một từ khóa hoặc một công thức. Mẹo: Nhìn vào bộ chọn: bộ chọn thứ n-loại () để chọn phần tử là đứa trẻ thứ n, thuộc loại được chỉ định, của cha mẹ của nó, đếm từ đứa trẻ cuối cùng. Look at the :nth-last-of-type() selector to select the element that is the nth child, of a specified type, of its parent, counting from the last child.
Hỗ trợ trình duyệtCác số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ hoàn toàn bộ chọn.
Bộ chọn | | | | | |
---|
: thứ n-last-child () | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS Cú pháp : thứ n-last-child (số) {& nbsp; & nbsp; css khai báo;} demo css declarations; } Demo
Nhiều ví dụ hơnThí dụChỉ định màu nền cho mọi yếu tố là con thứ hai của cha mẹ, đếm từ đứa trẻ cuối cùng: p: nth-last-child (2) {& nbsp; & nbsp; nền: màu đỏ; } Hãy tự mình thử » background: red; } Thêm ví dụ "hãy thử nó" dưới đây. background: blue; } Hãy tự mình thử » Thí dụChỉ định màu nền cho mọi yếu tố là con thứ hai của cha mẹ, đếm từ đứa trẻ cuối cùng:
p: nth-last-child (2) {& nbsp; & nbsp; nền: màu đỏ; } Hãy tự mình thử » background: red; } Hãy tự mình thử » Xem thảo luận Cải thiện bài viết Lưu bài viết ĐọcBàn luậnXem thảo luận Cải thiện bài viết Lưu bài viết Đọc This article explains the :not(:last-child):after selector. This selector does not select the element after the last child element. It is mostly used to add the content after every child element except the last. Example 1: This example creates a simple div element. It does not uses
:not(:last-child):after selector. HTML<!DOCTYPE html>
< html >
< head >
< :nth-last-child(n) 1>
:nth-last-child(n) 3:nth-last-child(n) 4
:nth-last-child(n) 5:nth-last-child(n) 6
:nth-last-child(n) 5:nth-last-child(n) 8
:nth-last-child(n) 5<!DOCTYPE html> 0
:nth-last-child(n) 5<!DOCTYPE html> 2
:nth-last-child(n) 5<!DOCTYPE html> 4
:nth-last-child(n) 5<!DOCTYPE html> 6
:nth-last-child(n) 5<!DOCTYPE html> 8
:nth-last-child(n) 5< 0
:nth-last-child(n) 5< 2
:nth-last-child(n) 5< 4
:nth-last-child(n) 5< 6
:nth-last-child(n) 5< 40
:nth-last-child(n) 3html 0
:nth-last-child(n) 5html 2
:nth-last-child(n) 5html 4
:nth-last-child(n) 5html 6
:nth-last-child(n) 5html 8
:nth-last-child(n) 5> 0
:nth-last-child(n) 3< 8
> 4:nth-last-child(n) 1>
> 4head >
< < 1>
< < 1 :nth-last-child(n) 1< 7< 54>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
:nth-last-child(n) 3< < 83< 96< 83>
< < 1 :nth-last-child(n) 1< 7< 54>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
> 4< 5>
< < 1 :nth-last-child(n) 1< 7< 54>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
:nth-last-child(n) 3< < 83< 96< 83>
> 4< 1>
> 4html >
Output: Các trình duyệt được hỗ trợ: After applying the pseudo selector :not(:last-child):after to the above example. HTML<!DOCTYPE html>
< html >
:nth-last-child(n) 5< 40
< :nth-last-child(n) 1>
:nth-last-child(n) 3:nth-last-child(n) 4
:nth-last-child(n) 5:nth-last-child(n) 6
:nth-last-child(n) 5:nth-last-child(n) 8
:nth-last-child(n) 5<!DOCTYPE html> 0
:nth-last-child(n) 5<!DOCTYPE html> 2
:nth-last-child(n) 5<!DOCTYPE html> 4
:nth-last-child(n) 5<!DOCTYPE html> 6
:nth-last-child(n) 5<!DOCTYPE html> 8
:nth-last-child(n) 5< 0
:nth-last-child(n) 5< 2
:nth-last-child(n) 5< 4
:nth-last-child(n) 5< 6
:nth-last-child(n) 3< 8
:nth-last-child(n) 3html 0
:nth-last-child(n) 5html 2
:nth-last-child(n) 5html 4
:nth-last-child(n) 5html 6
:nth-last-child(n) 5html 8
:nth-last-child(n) 5> 0
:nth-last-child(n) 3< 8
:nth-last-child(n) 3<!DOCTYPE html> 08
:nth-last-child(n) 5<!DOCTYPE html> 10
:nth-last-child(n) 3< 8
> 4:nth-last-child(n) 1>
> 4head >
< < 1>
< < 5 < 6< 7< 8>
:nth-last-child(n) 3< < 5 < 6< 7head 5head 6< 5>
:nth-last-child(n) 3< < 5 < 6< 7head 5head 6< 5>
> 4< 5>
< < 5 < 6< 7< 8>
:nth-last-child(n) 3< < 5 < 6< 7head 5head 6< 5>
:nth-last-child(n) 3< < 5 < 6< 7head 5head 6< 5>
> 4< 5>
< < 5 < 6< 7< 8>
:nth-last-child(n) 3< < 5 < 6< 7head 5head 6< 5>
:nth-last-child(n) 3< < 5 < 6< 7head 5head 6< 5>
> 4< 5>
> 4< 1>
< < 5 < 6< 7< 8>
Output: Explanation: > 4html Selects all the elements with class ‘inner-div’ inside elements with ‘div’ class. Here, all three divs have class ‘div’ with two children divs with class ‘inner-div’. It selects all six div element with class name
‘inner-div’.- :not(:last-child)
- .div .inner-div: Chọn tất cả các yếu tố với lớp ‘bên trong các phần tử bên trong với lớp‘ Div. Ở đây, cả ba div đều có lớp ‘Div, với hai đứa trẻ div với lớp’ nội tâm. Nó chọn tất cả sáu phần tử div với tên lớp ‘bên trong div.
- Bộ chọn: không () loại trừ phần tử được truyền cho nó từ lựa chọn.
- : Bộ chọn con cuối cùng chọn đứa trẻ cuối cùng.
- Kết hợp hai bộ chọn trên này để loại trừ những đứa trẻ cuối cùng (div bên trong) của mỗi div cha mẹ khỏi lựa chọn. This is a great selector to add content (or sometimes, even block-level elements) after the selected elements (Here the first inner-div
in every set of inner-divs). So, the content ‘not in the bottom div’ is indeed only added in the top div and not in the bottom div.
: Sau đây là một bộ chọn tuyệt vời để thêm nội dung (hoặc đôi khi, thậm chí các phần tử cấp khối) sau các phần tử được chọn (ở đây là phần bên trong đầu tiên trong mỗi bộ các bộ phận bên trong). Vì vậy, nội dung ‘không ở DIV phía dưới thực sự chỉ được thêm vào div trên cùng chứ không phải ở DIV phía dưới. Ví dụ 3: & nbsp; & nbsp;<!DOCTYPE html>
< html >
< head >
< :nth-last-child(n) 1>
:nth-last-child(n) 3< 28
:nth-last-child(n) 5< 30
:nth-last-child(n) 5< 32
:nth-last-child(n) 5< 34
:nth-last-child(n) 3< 8
:nth-last-child(n) 3< 38
HTML :nth-last-child(n) 3< 8
> 4:nth-last-child(n) 1>
> 4head >
:nth-last-child(n) 5< 40
< < 1 :nth-last-child(n) 1< 7< 54>
< < 67< 68< 67>
< < 5< 74< 5>
< < 79>
:nth-last-child(n) 3< < 83< 84< 83>
:nth-last-child(n) 3< < 83< 90< 83>
< < 58 :nth-last-child(n) 1< 7< 61< 62< 58>
:nth-last-child(n) 3< < 83html 02< 83>
:nth-last-child(n) 3< < 83html 08< 83>
> 4< 79>
> 4< 1>
Output: :nth-last-child(n) 3< < 83< 96< 83>
- Các trình duyệt được hỗ trợ:
- Google Chrome
- trình duyệt web IE
- Firefox
- Safari
Opera |