Help with Flexbox Nav Bar.

I am a beginner in CSS and I wanted to create a navbar. I made an absolute div with css and used flex bot to justify it evenly. but the main Nav with the links is not in the center of the page, how can I fix it? Thanks a lot.
10 Replies
b1mind
b1mind2y ago
Please provide a minimal example or some code, all anyone can do is guess without.
Azyrum
Azyrum2y ago
try space-between
Strike
StrikeOP2y ago
The whole navbar is an absolute div with margin in the sides. this div has display:flex withjustify-content: space-evenly. In this div there are 3 elements: the social links, the navigation and the logo. I want the navigation to be in the center of the absolute div but it's not. Tried, still isn't in the center.
Azyrum
Azyrum2y ago
copy the navbar into a codepen or a jsfiddle
Strike
StrikeOP2y ago
Complicated for me, it's in a project and is dependent on svgs and other react components. I think it is causing because the first element in the flexbox and the last are not the same width, but I'm not sure if it's really related.
vince
vince2y ago
Yea thats the case I believe You're probably going to have to use grid and use something like grid-template-columns: repeat(3, 1fr) Flex allows its children to take up as much width as they need, whereas grid is explicit in how much space each child should get. So grid is probably the answer here https://codepen.io/vince1444/pen/JjeWpVe Not responsive on mobile*
Strike
StrikeOP2y ago
That's the only fix that will work? Maybe I can make the centered element relative and just move it to center it horisontally?
vince
vince2y ago
That's even less responsive
Kevin Powell
Kevin Powell2y ago
Postion absolute on the middle one would work, but raises so many potential problems I wouldn't do it. I think vince's solution with a grid is the easiest solution tbh.
Strike
StrikeOP2y ago
Thx
Want results from more Discord servers?
Add your server