susannelson — 2013-12-01T00:39:38-05:00 — #1
I am customizing this theme: http://demo.studiopress.com/minimum/ .
I am trying to make the header (the part with the logo and menu) just 1140px wide instead of 100% and make it centered, but I also want it to remain fixed at the top of the screen. If I remove position: fixed, it will center, but with that applied, it will not.
Is there a workaround for this type of thing?
marplo — 2013-12-01T01:48:38-05:00 — #2
Try this css code:
/* center the element */
/* give it dimensions */
ralphm — 2013-12-01T06:48:18-05:00 — #3
That's a nice solution, @MarPlo. (It also works with the required 1140px width.)
Another option would be this (although I think I prefer MarPlo's):
paulob — 2013-12-01T08:18:28-05:00 — #4
The downside of that technique is that as you close the window the left side of the element slides off the left side of the window and is unreachable. Some people used to center whole pages like that and it's a bit of nightmare on smaller screens.:)
I usually use the same technique as MarPlo for both fixed and absolute elements. As long as the element has a width (or a max-width) then left:0 and right 0 will center the element within the containing block (as will top:0 and bottom:0 vertically center the element with a fixed height). It doesn't work in IE7 though and if IE7 compatibility is needed another option is simply to nest a static element of the desired width inside a 100% wide fixed element and center it in the normal way.
susannelson — 2013-12-03T06:27:37-05:00 — #5
Thanks so much, everyone! That solution works beautifully.