Skip to content

Truly centering the menu in Navbar? #36486

Answered by SamuelMiller
SamuelMiller asked this question in Q&A
Discussion options

You must be logged in to vote

I found this excellent tutorial, which uses using display : grid instead of display : flex to center. (https://chrisbracco.com/css-truly-center-a-single-child-element-horizontally-when-siblings-are-present/).

The author explains the central issue, "The “centered” child element is only horizontally centered within the remaining space in the parent element, and not the “true center” of the parent element. In this case the width of the centered element is equal to the width of the parent element minus any sibling element(s). The centered element can only be “truly centered” if the width of child elements on both the left and right of it are equal."

The tutorial solution boils down to this:

<…

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by SamuelMiller
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@SamuelMiller
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants