Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Control Z-Index and Overlapping Element | Mastering CSS Positioning
Advanced CSS Techniques

book
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:

html

index.html

css

index.css

copy
<!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>

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.

html

index.html

css

index.css

copy
<!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>

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 11

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt