EN
CSS - style last element only
0 points
In this article, we would like to show you how to style the last element only using CSS.
Quick solution:
xxxxxxxxxx
1
element:last-child {
2
/* style properties here */
3
}
In this example, we create a style for the last div
element only using :last-child
.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div:last-child {
7
background: yellow;
8
}
9
10
</style>
11
</head>
12
<body>
13
<div>div 1</div>
14
<div>div 2</div>
15
<div>div 3</div>
16
</body>
17
</html>