EN
CSS - expanding list on hover
0 points
In this article, we would like to show you how to create an expanding list on hover using CSS.
Below we create an expanding list, that expands on hover adjusting the height to the number of elements in the list.
Runnable example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
.menu .list {
7
max-height: 0; /* height at the start */
8
overflow: hidden; /* required to hide li elements */
9
transition: 1s; /* works both ways */
10
}
11
12
.menu:hover .list {
13
max-height: 300px; /* max height when expanded */
14
}
15
16
</style>
17
</head>
18
<body style="height: 120px">
19
<div class="menu">
20
Hover to expand the list:
21
<ul class="list">
22
<li>list item</li>
23
<li>list item</li>
24
<li>list item</li>
25
<li>list item</li>
26
<li>list item</li>
27
</ul>
28
</div>
29
</body>
30
</html>