Absolutely positioned element behaving weirdly - Building a Penguin Course

On step 9 of [Learn CSS Transforms by Building a Penguin] it was asked to set the position of the .ground element to absolute. Ok. Next it was added a div.penguin on top of the div.ground in the html. Then for some reason the .ground stays below the the .penguin as if it had a position set to stactic.
I tried googling it but I don’t know to word it. Shouldn’t the .ground element get out of the “flow” and position itself on the top-left corner of the body?

  **Your code so far**
/* file: index.html */
<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8" />
  <link rel="stylesheet" href="./styles.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <div class="penguin"></div>
  <div class="ground"></div>
/* file: styles.css */
body {
background: linear-gradient(45deg, rgb(118, 201, 255), rgb(247, 255, 222));
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
overflow: clip;

.penguin {
width: 300px;
height: 300px;


.ground {
width: 100vw;
height: 400px;
background: linear-gradient(90deg, rgb(88, 175, 236), rgb(182, 255, 255));
z-index: 3;
position: absolute;
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Learn CSS Transforms by Building a Penguin - Step 12

Link to the challenge:

Ya, you aren’t the only one to ask this question. It shows that you are paying attention :slight_smile: If you don’t set a top/left/bottom/right on an absolutely positioned element it still behaves as a static element. This course never sets any of those positions on this element. In fact, at the end it uses a negative margin top to move it up a little instead of using absolute positioning. I think the only reason it is set to absolute positioning is to use z-index on it. So in that case, a better choice would have probably been relative positioning.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.