`:
```css
#yellow {
/* Other styles above */
position: relative;
left: 0px;
top: 0px;
}
```
**What Happens?**
- If you said **_nothing_**, you are correct! We told the box to move `0px` from the left and `0px` from the top of where it was relatively positioned. In other words...where it started. Therefore, it didn't move.
**Now try the following:**
- `left: 100px;` → Moves the yellow box **100 pixels away from the left edge** of its original position
- `top: 20px;` → Moves the yellow box **20 away from the top** of its original position.
- The **blue box does not move**—only the yellow box is affected!
Try experimenting with **negative values** (`left: -50px;`) to see how the movement changes!
---
When an element has **`position: absolute`**, it moves **relative to its nearest positioned parent** (a parent element with `relative`, `absolute`, or `fixed` positioning).
**If no parent has a set position**, the element is positioned **relative to the entire page ``**.
Let’s apply **absolute positioning** to the **blue** `
`:
```css
#blue {
/* Other styles above */
position: absolute;
left: 0px;
top: 0px;
}
```
**What Happens?**
- The **blue box jumps to the very top-left corner** of the page (`left: 0px;`, `top: 0px;`).
- Since **absolute positioning removes it from the normal flow**, the blue box now **overlaps the yellow box** instead of stacking below it.
**Now try the following:**
- Change `left: 100px;` → Moves it **100px to the right**.
- Change `top: 50px;` → Moves it **50px down**.
- Change `top: 20px;` → `bottom: 20px;` Now, instead of moving down from the top, the box moves **up from the bottom**.
Try experimenting with **negative values** `left: -20px;` to see how the movement changes!
TIP: After updating your code, click the "Run" or "Rerun" button in CodePen to make sure your changes take effect. Then, check View Test Results to see if your updates pass!
---
When an element has **`position: fixed`**, it **stays in place on the screen**, no matter how much you scroll.
Unlike `relative` or `absolute`, a **fixed element is not affected by other elements and does not move with the page**—it remains stuck to a set position relative to the **viewport** (the visible screen area).
Let's’ll apply **fixed positioning** to the **blue** `
`:
```css
#blue {
/* Other styles above */
position: fixed;
left: 0px;
top: 0px;
}
```
Now let's increase the hight of the body so we have room to scroll. Try it!
```css
body {
height: 1000px;
}
```
**What Happens?**
- The **blue box is locked in the top-left corner** of the screen (`left: 0px;`, `top: 0px;`).
- **Even when you scroll**, the blue box **stays in place** instead of moving with the page.
- The yellow box will **scroll normally**, but the blue box does not- it is _fixed_.
TIP: After updating your code, click the "Run" or "Rerun" button in CodePen to make sure your changes take effect. Then, check View Test Results to see if your updates pass!
---
Which `position` value moves an element relative to where it originally appears on the page, without affecting other elements?
---
Which `position` value keeps an element locked in place on the screen, even when the page is scrolled?
---
Which `position` value removes an element from the normal document flow and positions it relative to its closest positioned parent (or the entire page if no parent is positioned)?
---
Now, let’s shift our focus to the **most important part of the page—Hannah’s artwork!** The image gallery looks great, but with a few refinements, we can make it **stand out** and look more polished.
**1. In your HTML, find the `
` that holds all the artwork images. Add an `id="image-container"` to this `
`.**
**2. Using the CSS selector: `#image-container img` create a rule that targets each image inside `#image-container`.**
**3. Apply these styling properties:**
- **Rounded corners: Add `border-radius: 8px;` to make the image edges slightly curved.**
- **Subtle shadow effect: Add `box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);` to create a soft, 3D effect that makes the images pop off the page.**
Once you apply these changes, Hannah’s artwork will look even more professional and visually appealing!
TIP: After updating your code, click the "Run" or "Rerun" button in CodePen to make sure your changes take effect. Then, check View Test Results to see if your updates pass!
---
Hannah’s site is looking great! But wait… we didn’t actually use any of our new positioning techniques?
That’s because in **modern web development**, we focus on making pages **responsive**—meaning they look good on **all screen sizes**, from desktops to mobile devices. While `position` is useful in some cases, it’s not the best tool for **structuring entire layouts**.
There’s a **better way** to control the placement of multiple elements: **Flexbox!**
In our next lesson, we’ll explore **Flexbox**, a powerful tool that makes **aligning, spacing, and organizing layouts easier and more flexible**.
For more information or resources on CSS display and position properties, check out:
-
Learn Layout: The `display` Property
-
Learn Layout: Position
</textarea>