From the course: CSS Layouts: From Float to Flexbox and Grid
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Position: Fixed, sticky, and static - CSS Tutorial
From the course: CSS Layouts: From Float to Flexbox and Grid
Position: Fixed, sticky, and static
- [Speaker] Continuing from the last exercise. Let's jump back in with fixed positioning. Go to the nav selector block on line 14 and add-in position fixed. We're going to create a navbar that's always displayed in the viewport, even on page scroll, but it looks like it just disappeared. It didn't. It's actually under the main element. Remember, we talked about position in the z-index, right? Well, we added position relative to the main element, and it comes after the nav in the HTML. So by default, it has a higher stack order. So the nav is just underneath the main content. We can just add a z-index value to the nav to make sure it stays on top. And often when creating a fixed nav, it's good to give it a high number because we want that to always be on top of all elements. So let's add that in. And the navigation bar is back. With position fixed and absolute. If the block element doesn't have a width applied to it,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Inline and block elements1m 53s
-
(Locked)
The box model properties3m 32s
-
(Locked)
The display property5m
-
(Locked)
The box model and layouts3m 17s
-
(Locked)
The float property3m 19s
-
(Locked)
Clearing floats5m 32s
-
(Locked)
Setting up your project2m 45s
-
(Locked)
Exercise: Build a layout with float6m 29s
-
(Locked)
Position: Relative and absolute5m 15s
-
(Locked)
Position: Fixed, sticky, and static4m 13s
-
(Locked)
-
-
-