Home > Net >  How to make navbar fixed to top and align items to center?
How to make navbar fixed to top and align items to center?

Time:04-14

I have tried aligning navbar to center and setting the position as fixed but my navbar shifts to left and it's width also decreases. Can anyone help how to do these at the same time? Before setting position to fixed

After setting position to fixed

CodePudding user response:

When you set a position to fixed, the width will always decrease. I'm not going to get into why since you can search it up. Additionally, because the width shrank, it will also go left since that's the default.

What you can do is manually set the width of the navbar to width: 100% in CSS. This will make your navbar span the entire width of the website as it should. For reference, your CSS should look like this:

nav {
  width: 100%;
  position: fixed;
}

CodePudding user response:

I dont have all your code but you can try this. Then let me know

nav {
  width: 100%;
  position: fixed;
  left:0;
  right:0
  text-align:center;
  margin:0 auto;
}

  • Related