Text-align: center


How do you align something to the centre of a page when the aligning doesn’t including a vertical navbar?

i.e align to center but ignoring the first 100px or so of the navbar.

This also leads into my next question. If I want flexbox on my page, how can I get flexbox to ‘see’ the navbar instead of going under it?


For the first question, you can use one div for the navbar and one for the rest of the page and then make this div use flexbox and use justify-content to center align text. And can you please paste your html and css so we can help with the second question.

The navbar and main div should also be in a flexbox container otherwise they will render below each other. Is this what you mean with the second question?

1 Like

So it’s fine to wrap a nav within a div? I always feel I’m using too many elements. But what you say makes sense. Obviously the nav being inline and div being block means I’ll get the effect I want.

So simple! You also answered my second question. By wrapping the nav in a div, the flexbox will know work it’s measurements from the nav div. (or so I hope!)

1 Like