-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
62 lines (43 loc) · 1 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: ":last-child"
slug: Web/CSS/:last-child
---
{{CSSRef}}
La [pseudo-classe](/fr/docs/Web/CSS/Pseudo-classes) **`:last-child`** permet de cibler un élément qui est le dernier enfant de son parent.
```css
/* Cible n'importe quel élément <li> tant que */
/* celui-ci est le dernier enfant de son élément */
/* parent */
li:last-child {
background-color: lime;
}
```
> [!NOTE]
> En CSS3, l'élément ciblé devait avoir un élément parent, cette restriction a été levée en CSS4.
## Syntaxe
{{csssyntax}}
## Exemples
### CSS
```css
li:last-child {
background-color: lime;
}
```
### HTML
```html
<ul>
<li>Cet élément n'est pas vert !</li>
<li>Celui-ci est vert.</li>
</ul>
```
### Résultat
{{EmbedLiveSample('Exemples', '100%', 100)}}
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}
## Voir aussi
- {{cssxref(":first-child")}}
- {{cssxref(":nth-child")}}
- {{cssxref(":last-of-type")}}
- {{CSSxRef(":-moz-last-node")}} {{Non-standard_Inline}}