Challenge: Control Z-Index and Overlapping Element
Task
Create a visually appealing background for the website using an illustration composed of 5 different images. All images are correctly positioned within the frame of the parent div
element. Your task is to adjust the stacking order using the z-index
property to achieve the desired view outlined in the image below:
index.html
index.css
99
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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="container">
<img
class="sun"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/sun.png"
alt="sun"
width="160px"
/>
<img
class="birds"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/birds.png"
alt="birds"
width="130px"
/>
<img
class="cloud"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/cloud.png"
alt="clouds"
width="340px"
/>
<img
class="frog"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/frog-.png"
alt="frog"
width="60px"
/>
<img
class="pond"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/pond.png"
alt="pond"
width="340px"
/>
</div>
</body>
</html>
99
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
img {
position: absolute;
}
.pond {
bottom: -60px;
right: -20px;
}
/* --------------- Make changes below this line --------------- */
.birds {
top: 70px;
left: 20px;
___: ___; /* Change this line */
}
.cloud {
top: -130px;
left: -35px;
}
.sun {
right: 40px;
___: ___; /* Change this line */
}
.frog {
bottom: 75px;
right: 130px;
___: ___; /* Change this line */
}
/* --------------- Make changes above this line --------------- */
/* Not the current focus */
.container {
margin: 0 auto;
To change the stacking order of the images within the parent div
element, use the z-index
property. A higher z-index
value, such as 1
, raises the element above others in the stacking context, making it visible in the foreground.
index.html
index.css
99
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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="container">
<img
class="sun"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/sun.png"
alt="sun"
width="160px"
/>
<img
class="birds"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/birds.png"
alt="birds"
width="130px"
/>
<img
class="cloud"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/cloud.png"
alt="clouds"
width="340px"
/>
<img
class="frog"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/frog-.png"
alt="frog"
width="60px"
/>
<img
class="pond"
src="https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/advanced+css+techniques/positioning+section/pond.png"
alt="pond"
width="340px"
/>
</div>
</body>
</html>
99
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
img {
position: absolute;
}
.pond {
bottom: -60px;
right: -20px;
}
.birds {
top: 70px;
left: 20px;
z-index: 1;
}
.cloud {
top: -130px;
left: -35px;
}
.sun {
right: 40px;
z-index: 1;
}
.frog {
bottom: 75px;
right: 130px;
z-index: 1;
}
/* Not the current focus */
.container {
margin: 0 auto;
width: 400px;
height: 400px;
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 11
Ask AI
Ask anything or try one of the suggested questions to begin our chat