# Setting the navigation bar to "position: fixed;" messes up website

**URL:** <https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357>\
**Category:** General\
**Created:** [May 24, 2020, 4:05am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357 "2020-05-24T04:05:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExquisiteToast](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/exquisitetoast/32/150307_2.png) [@ExquisiteToast](https://forum.freecodecamp.org/u/ExquisiteToast)\
**Post date:** [May 24, 2020, 4:05am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/1 "2020-05-24T04:05:32Z")

</div>

Whenever I set the navbar to fixed it moves the HR element beneath it, above it and it moves my h1 up. Sorry if this is a really dumb question but I can’t find an answer to it anywhere else. [CodePen Webpage](https://codepen.io/ExquisiteToast/pen/zYvbaJQ) and this is how it is sopposed to look like:

 ![image](https://global.discourse-cdn.com/freecodecamp/original/3X/8/9/898cef2766807af79486964c8d02b7adaa7cd163.png)

---

<div class="post-metadata">

**Author:** ![kerafyrm](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kerafyrm](https://forum.freecodecamp.org/u/kerafyrm)\
**Post date:** [May 24, 2020, 4:20am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/2 "2020-05-24T04:20:01Z")

</div>

That’s because **position: fixed** “removes” your nav ul from all it’s parent elements.

It doesn’t remove it physically in the html, but the rules of its parent elements no longer impact it.

What’s the goal here?

---

<div class="post-metadata">

**Author:** ![kerafyrm](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kerafyrm](https://forum.freecodecamp.org/u/kerafyrm)\
**Post date:** [May 24, 2020, 4:20am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/3 "2020-05-24T04:20:35Z")

</div>

If you want it to look like the picture simply remove the position: fixed.

---

<div class="post-metadata">

**Author:** ![ExquisiteToast](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/exquisitetoast/32/150307_2.png) [@ExquisiteToast](https://forum.freecodecamp.org/u/ExquisiteToast)\
**Post date:** [May 24, 2020, 4:23am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/4 "2020-05-24T04:23:03Z")

</div>

The goal is to keep it fixed and still have the HR element below it. In the picture it isn’t fixed to the top

---

<div class="post-metadata">

**Author:** ![kerafyrm](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kerafyrm](https://forum.freecodecamp.org/u/kerafyrm)\
**Post date:** [May 24, 2020, 4:30am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/5 "2020-05-24T04:30:19Z")

</div>

Then a few things you need to do:

If you want the HR element to be the top element below the navbar then you need to check the height of the navbar as it is now. (which is 84px).

So you first give your hr element margin-top: 84px;  
Next you remove the position: fixed from nav ul and place it on nav element.  
You’ll also need: top: 0, left: 0, right: 0

This will cause the fixed element to be on top but push the hr element and everything below it down 84px so it’s not on top.

Next you have to prevent the text from bleeding through when you scroll down in mobile.

So you’ll have to add z-index: 400 (or any number \> 1) to the nav element.  
Then finally you’ll have to add background color #f2f2f0 to the nav element.

That should do it.

You have a lot of bad habits in your code. ie., floats,   
,

* * *
 is naming a few. But the instructions above should help you with what you asked for.

---

<div class="post-metadata">

**Author:** ![ExquisiteToast](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/exquisitetoast/32/150307_2.png) [@ExquisiteToast](https://forum.freecodecamp.org/u/ExquisiteToast)\
**Post date:** [May 24, 2020, 4:31am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/6 "2020-05-24T04:31:43Z")

</div>

Thanks, I’m still beginning into the world of web developement but I hope to improve my skills. I’ll try this out.

---

<div class="post-metadata">

**Author:** ![ExquisiteToast](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/exquisitetoast/32/150307_2.png) [@ExquisiteToast](https://forum.freecodecamp.org/u/ExquisiteToast)\
**Post date:** [May 24, 2020, 4:34am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/7 "2020-05-24T04:34:07Z")

</div>

Also I removed the floats and I’ll make sure I just have whole numbers

---

<div class="post-metadata">

**Author:** ![ExquisiteToast](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/exquisitetoast/32/150307_2.png) [@ExquisiteToast](https://forum.freecodecamp.org/u/ExquisiteToast)\
**Post date:** [May 24, 2020, 4:37am UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/8 "2020-05-24T04:37:37Z")

</div>

It worked, thanks for the help.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:52pm UTC](https://forum.freecodecamp.org/t/setting-the-navigation-bar-to-position-fixed-messes-up-website/393357/9 "2021-06-01T18:52:14Z")

</div>

Closed on June 1, 2021, 6:52pm UTC


