Hate to post here, but i have tried all I can think of. Can someone help me out with CSS to center the primary menu?

Comments

jeremycaldwell’s picture

I tried myself and spent about 15minutes on it with no luck. I'm sure it can be done though, just takes some reworking of the CSS.

jcmarco’s picture

To center a block you need to use this trick (is the same than the skinner style: center block)
float: none;
margin-left: auto;
margin-right: auto;

But it need to have width, if you set a width to it then it works (with a skinner block you need to set a width as well)
width:300px; For example!

With this theme:

#primary-menu {
overflow:visible; //original one
float:none;
margin-left:auto;
margin-right:auto;
width:300px;
}

stephthegeek’s picture

Status: Active » Fixed

Thanks for helping, jcmarco!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

stephthegeek’s picture

Status: Closed (fixed) » Needs review

An IRC conversation brought this up again and this code appears to do the trick without needing to set a fixed width. If someone has a chance to give it a try, please let us know if you encounter any issues and if not, we'll add it to the documentation:

#primary-menu {
  position: relative;
  left: 50%;
  width: auto;
}

#primary-menu-inner {
  float: left;
  position: relative;
  right: 50%;
  width: auto;
}
jeremycaldwell’s picture

Yup, that code works perfect stephthegeek! Nice short code and very effective, good find!

stephthegeek’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

matt_stoltz’s picture

Status: Closed (fixed) » Needs review

The code submitted by stephthegeek works great, kindof. The problem I'm in countering on my side when I implement that block of code is an unwanted bottom scroll bar. The scroll bar only appears in resolutions smaller then my set 1920x1080. Any resolution smaller then that, and there is a scroll bar at the bottom that just scrolls over the right, revealing empty "white space".

jeremycaldwell’s picture

@matt_stoltz, can you post a link to your site so we can see what CSS is being applied to your menu and what might be causing the horizontal scroll? Not sure a screenshot would help since it could be anything.

matt_stoltz’s picture

Its off of most of my sites, but i believe www.stylesforkitchen.com should still have it up.

matt_stoltz’s picture

www.myhealthylifestylenews.com has the issue on it.

jeremycaldwell’s picture

Since you aren't using dropdown menus it would be safe to add this bit of CSS to your theme's local.css file to get rid of the scroll bar.

#header-primary-menu-wrapper {
  overflow: hidden;
}

Hope that helps!

matt_stoltz’s picture

So far so good, tyvm!

jeremycaldwell’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ytin’s picture

Wrong thread.

itserich’s picture

Thanks, this worked for me as well, # 5 elastic centered primary menu.

ratinakage’s picture

#5 works!

Thanks... :)