It is perfectly centred.
The extra space at the bottom is the margin on your ul and not part of the centring area as such. Set margin:0 to the ul in relevant media queries.
.header nav ul{margin:0;}
Remember uls had default margin and padding and you need to control them explicitly,
With the margin:0 in place the gap under the logo disappears (apart from the margin you have on the logo).
Without flex-wrap the menu will stay on one single line. That means you have your logo then your toggle then your 100% nav. The nav is hidden but still takes up space as visibility:hidden does not remove the item from the flow unlike display:none. Therefore if you could see your nav it would be pushing out the right side of the viewport.
In this scenario the margin-left:auto on the toggle has no effect because there is no free space on that row. There is a logo, a toggle and a 100% nav. They are all squashed together in one line.
As soon as you add flex-wrap to the parent then the 100% wide nav is moved to a new line and the the toggle has empty space all the way on its right to the viewport edge. The margin-left:auto pushes the toggle to the right edge because now there is nothing in its way.
If you made your nav visible it might be easier for you to see what’s happening.
You want to avoid fixed heights on fluid content most of the time. They only complicate things and are not fluid enough for responsive design.
You are not hiding the overflow on the ul so when the transition occurs and you change the height then the elements no longer fit in the space available and show outside until they fade away.
I’m not keen on the height animation on that menu as it fixes you to a height and indeed if someone resizes text or you have more or less menu items then your menu fails.
You can use the max-height trick and use a max-height larger than you need in order to get some animation and to allow some leeway with the menu size.
This is the code you need.
@media screen and (max-width: 1500px){
.header nav ul{
overflow:hidden;
height:auto;
max-height:0;
transition:all .5s ease;
}
.header nav #menu-toggle:checked ~ ul{
height:auto;
max-height:35rem;
}
}
However I am not keen on that method either as although it is miles better than the height method it uses a magic number for the max-height and magic numbers need to be avoided at all costs.
Unfortunately in CSS there is no way to animate/transition from height:0 to height:auto as CSS does not animate auto measurements. I prefer to slide in menus from the side instead to avoid this issue.
These are very old and pretty rough demos but you should get the picture.
http://www.pmob.co.uk/temp2/template1/index.html