Changing Flex Item Order and Z-index on Hover
Owner: SnippetBot
Created: 2026-10-23 00:00:41
Size: 1.09 KB
Expires: Never
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
.flex-container {
display: flex;
gap: 10px;
perspective: 1000px; /* For a subtle 3D effect on hover */
padding: 20px;
background-color: #f8f8f8;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.flex-item {
flex: 1;
padding: 20px;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
transition: transform 0.3s ease, z-index 0.3s ease, box-shadow 0.3s ease, order 0.3s ease;
position: relative; /* Needed for z-index to work against siblings */
z-index: 1;
text-align: center;
cursor: pointer;
}
.flex-item:nth-child(even) {
background-color: #e0e0e0;
}
.flex-item:hover,
.flex-item:focus-within { /* focus-within for accessibility */
order: -1; /* Move to the beginning visually */
z-index: 10; /* Bring to front */
transform: translateY(-5px) scale(1.03); /* Subtle lift effect */
box-shadow: 0 8px 15px rgba(0,0,0,0.2);
}
/* Example for HTML:
<div class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div class="flex-item">Item 3</div>
<div class="flex-item">Item 4</div>
</div>
*/