Can`t center vertically a Flexbox item .
So i am trying to make a header in react, (but focus on HTML and CSS in this point).
i have a DIV container in which all the header elements are placed:
And inside this Div i have an other DIV with the UL element for the menu. The HTML code is fine, i ll give you the CSS and describe the issue:
So i want inside the box2 to display a UL as a row in the center of the box2 element. The issue is that using property doesnt work to center vertically the UL element. It stays on top. I know its a noob question but i tried everything and i cant figure it out.
8 Replies
You haven't provided your HTML. You say that it is fine but, following your indications the items should be centered correctly which makes me think that you may have missed something or that there is something else going on.
It would be easier if you could add your code to a Codepen or similar so that we could see what you are actually doing.
Obviously I don't know the context but I would question why you need to wrap the ul inside a div 🤔 You seem to have multiple containers with flex when you may not actually need them.
And here it is how its displayed in browser via react app
OK, so from that we can see that in the Codepen it is centered correctly.
That means that there must be something else in the actual app that is influencing the display, for example a bottom margin on ul elements.
Have you looked at the inspector tool to see the styling on the UL element?
Yes!
It had margin-bottom set to 3 rem for some reason
So, why it had that set? I didn`t write anything, is it by default?
The inspector should give you some idea as to where that is defined. Something in the global CSS probably but without seeing the code base it is impossible to tell.
Its an expiremental project, the only css is here: