CORE CONCEPTS

CORE CONCEPTS

New

The Box Model

The Box Model

New

1:54

Intro to Web Layout

Intro to Web Layout

New

2:27

Display Settings

Display Settings

New

2:54

Padding & Margin

Padding & Margin

New

2:48

Width & Height Units

Width & Height Units

New

3:59

Floats & Clears

Floats & Clears

New

1:52

Flexbox & Grid

Flexbox & Grid

New

Intro to Flexbox

Intro to Flexbox

New

2:27

Centering Elements with Flexbox

Centering Elements with Flexbox

New

1:20

Equal Height Layouts with Flexbox

Equal Height Layouts with Flexbox

New

1:47

Grid layouts overview

Grid layouts overview

New

4:18

Flexbox vs. Grid

Flexbox vs. Grid

New

4:00

Advanced Layout

Advanced Layout

New

Positioning Overview

Positioning Overview

New

1:48

Relative Positioning

Relative Positioning

New

1:43

Absolute Positioning

Absolute Positioning

New

1:43

Fixed Positioning

Fixed Positioning

New

1:27

Z-Index

Z-Index

New

1:49

Overflow

Overflow

New

1:49

new course
CSS grid landing page tutorial (36min)

Lesson info

Lesson info

The position property allows you to move elements relative to: their current place in the document (relative), a parent element (absolute), or the viewport (fixed). Here we’ll be covering fixed position.

Fixed-positioned elements are completely removed from the document flow — meaning they no long touch or push other elements around them. They're pinned to the viewport, so they stay in place as the user scrolls, unlike absolute elements which are pinned to one of their parent elements.

We’ll be covering these concepts in this lesson:

  1. Enabling fixed position‍
  2. ‍Positioning values
  3. ‍Z-index

And then bring it all together with an example.

Explore this project

Want to dig into the project featured in this video and see how everything is put together? We've included the full project we used when making this lesson, and we've shared the link right under this very paragraph.

View and clone this projectDownload lesson assets
Clone this projectDownload project assets

Transcript

Just like absolute Positioning, Fixed Positioning completely removes an element from the document flow (and doesn't leave a seat warmer). But where absolute Positioning can take cues from one of its parent elements, Fixed means our element Position is based around the viewport itself.

Here's a navbar on a page. And we can scroll through the page to see that our elements scroll with the document.

Let's select the navbar. And sometimes clicking the navbar gets us one of its child elements, so we can use the navigation at the bottom to make sure the actual navbar is selected.

From here, let's set the Position to Fixed. And right away, we see something happen: the navbar collapses a bit. There are two ways to deal with this:

1. We can set the width of our navbar to 100%. And we can set our Position to 0 pixels from the top. If we scroll, it works fine.

And 2. We can undo what we just did, and instead, set the top, left, and right to 0 pixels by using this nifty button.

Now why are we doing 0 pixels from the top? We keep saying that, why is it important? Let's remove that for a second. And let's go into the Navigator and move our navbar down on the page a bit, maybe into a section here. And if we scroll around, we see that it's not quite what we intended.

Adding 0 pixels from the top (or simply using the preset button) makes everything behave as expected.

So, fixed Positioning removes an element from the document flow, and Positions it around the viewport.