So I just made some changes to a website for the header and I am trying to figure out how I can keep the menu centered now that my header is 100% width of page which was a necessary change for the look of the site. I am currently centering the logo and menu with margin-left which at my full screen size of 1920px and it looks fine, but if I shrink the browser window or if you view from a different screen resolution, blah! I have read around on some tutorials online, but am obviously missing something. Unfortunately, I am waiting for a reply from the owner who just changed the hosting account login info so I cannot show you the changes live online, but here is the code...
Hard to say what you have right now (with the code displaying as above) but I would strongly advise against using margin-left to center something. That will work on one resolution and not work on others.
Instead, you might want to try giving it an absolute position (where the wrapping div has a width of 100% and has relative positioning), position it left at 50% and then give it a negative margin that's HALF of the menu width.
@Senff...that will work but you have to set a menu width...and if you're going to do that then...
As I see it he has a logo and menu on the same level (as both are floated left) so he really needs to add a wrapper to these.
The margin: auto property will now work as he has set his logo and menu to have specific widths / margins and the width of the wrapper can be calculated.
Okay, thanks all. I tried Paulie-D's suggestion and it works, but now my header menu text attributes are not all functioning correct. It looks correct in CodePen except for the last link on right does not fit in provided space, but it fits fine in the browser. Those links look different in browsers though, strange. The font size is about half what it should be and when you hover over the links, an underline now appears? Everything else looks correct. Once again, I must be missing something. Thanks again for you help!
No, that was fine, still do not know why Codepen was having an issue with that as the browsers displayed it fine. I found the problem with the font attributes being incorrect. I needed to change the "header a:{" to "header a:links{" since all the text in the header wrapper were links, did not have to do this before putting them in a wrapper.
So I just made some changes to a website for the header and I am trying to figure out how I can keep the menu centered now that my header is 100% width of page which was a necessary change for the look of the site. I am currently centering the logo and menu with margin-left which at my full screen size of 1920px and it looks fine, but if I shrink the browser window or if you view from a different screen resolution, blah! I have read around on some tutorials online, but am obviously missing something. Unfortunately, I am waiting for a reply from the owner who just changed the hosting account login info so I cannot show you the changes live online, but here is the code...
After the necessary changes__
Thanks for and advice!
You have put in the example above
#header { width: 100%px; height: 98px; margin: auto;The width is either a fixed pixel size or a percentage, you can't specify both. In your case just get rid of the px,
Also center the the navigation by putting margin: 0px auto; instead of just margin: auto;
It would be to your advantage if you put your example into CodePen.
Hard to say what you have right now (with the code displaying as above) but I would strongly advise against using margin-left to center something. That will work on one resolution and not work on others.
Instead, you might want to try giving it an absolute position (where the wrapping div has a width of 100% and has relative positioning), position it left at 50% and then give it a negative margin that's HALF of the menu width.
A bit like this method: http://codepen.io/senff/pen/qcHEt
@Senff...that will work but you have to set a menu width...and if you're going to do that then...
As I see it he has a logo and menu on the same level (as both are floated left) so he really needs to add a wrapper to these.
The margin: auto property will now work as he has set his logo and menu to have specific widths / margins and the width of the wrapper can be calculated.
http://codepen.io/anon/pen/xeEbz
Okay, thanks all. I tried Paulie-D's suggestion and it works, but now my header menu text attributes are not all functioning correct. It looks correct in CodePen except for the last link on right does not fit in provided space, but it fits fine in the browser. Those links look different in browsers though, strange. The font size is about half what it should be and when you hover over the links, an underline now appears? Everything else looks correct. Once again, I must be missing something. Thanks again for you help!
http://codepen.io/anon/pen/fFrlA
I think that's because your
.menuis set to a fixed width of 650 pixels, which is not enough to hold all 6 menu items.No, that was fine, still do not know why Codepen was having an issue with that as the browsers displayed it fine. I found the problem with the font attributes being incorrect. I needed to change the "header a:{" to "header a:links{" since all the text in the header wrapper were links, did not have to do this before putting them in a wrapper.
Once again thanks for all the help!