7

Using Foundation, I'm trying to adjust the top-bar menu in order to have menu items looks something like that:

+-Parent container------------------------------------------------------------------+
|                                                                                   |
+-.top-bar--------------------------------------------------------------------------+
|              +-top-bar-section-+--------+--------+--------+--------+              |
|              |  Item  |  Item  |  Item  |  Item  |  Item  |  Item  |              |
|              |  menu  |  menu  |  menu  |  menu  |  menu  |  menu  |              |
|              |   01   |   02   |   03   |   04   |   05   |   06   |              |
|              +-top-bar-section-+--------+--------+--------+--------+              |
+-.top-bar--------------------------------------------------------------------------+
|                                                                                   |
|                                                                                   |
˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

This means that:

  1. Items have a fixed width
  2. Items may have one or more lines (usually no more than 3 lines), but they must be alway vertically centered.
  3. All items height must be the same as the highest item
  4. Submenus (dropdown) must open below the hovered item

I've tried several option (display set to table-cell or inline-block with vertical align set to middle) and looked around the web, but I can't find a solution that meet all the requirements above.

Anyone ever tried to do that?

Andrea Sciamanna
  • 1,404
  • 1
  • 15
  • 30
  • Are you on Foundation 3 or 4? Either way, the place to start is to use the "centered" class. See the "grid" section of the docs: http://foundation.zurb.com/docs/components/grid.html – vtacreative Jun 11 '13 at 15:36
  • Foundation 4. The "centered" class is for centering a grid element. Here I want to keep the – Andrea Sciamanna Jun 11 '13 at 16:31
  • 1
    I'm not sure to have understood why this question has been closed. It's a case that, I believe, other people may need to have solved. Maybe I didn't write in proper English (sorry, it's not my native language), but I don't think it's not constructive, ambiguous, vague, incomplete, overly broad, or rhetorical. Please clarify. – Andrea Sciamanna Jun 11 '13 at 19:13
  • 1
    Yeah I agree... I understood what you were asking just fine. Sometimes the folks at StackOverflow are way overzealous, kinda like hall monitors or what not. Oh well. – vtacreative Jun 11 '13 at 20:14
  • Thank you CL75. I hope someone will reopen this question. – Andrea Sciamanna Jun 11 '13 at 21:47

4 Answers4

3

I cannot resolve your issue, but I can explain why it is difficult to do with Zurb Foundation.

  • The way that buttons are implemented (and reused in the top-bar) in Zurb Foundation have the css display:inline-block set. This means that you cannot vertically align the text using vertical-align:middle This makes it impossible to automatically align buttons with multiline text.

  • The top-bar is not designed to have evenly spaced elements. You can use a ul.button-group.event-6 to get closer to your desired layout, but it will not work with all of your constraints. It is designed to have a Logo, a left menu and a right menu.

  • Setting the height is easy and can be done in css by applying height:80px for example to each of the buttons. However, the multiline text alignment will be to the top.

  • Submenus can be simulated with a.button.dropdown but again, it won't meet all of your constraints

  • The topbar functionality in foundation is contained mostly in a jQuery plugin in the foundation.topbar.js file. This would require a lot of modification to work in the way that you envision and would make your topbar likely incompatible with future and past versions of Foundation.

When trying to get your desired design to work with a specific framework you have a couple of options:

  1. realign your goals to fit within the confines of the framework (i.e. reduce your number of constraints or change the design slightly to accomidate the limitations of Foundation)

  2. use another framework that provides this functionality, check out this similar post about doing the same thing with bootstap

  3. look for another library to accomplish the desired functionality (in your case maybe look at jQuery Mobile Navbars

  4. write your own functionality

I this helps to explain some of the reasons why what you are trying to do is not possible with Zurb Foundation 3/4. If you resolve the issue it would be great if you posted back your solution as it seems many other people would like to do something similar.

Community
  • 1
  • 1
JAMESSTONEco
  • 2,051
  • 15
  • 21
2

Here is how to do it:

Add this to your CSS:

.top-bar-section ul {display: table; margin: 0 auto;}
.top-bar-section ul li {display: table-cell;}

Be sure it will override Foundations CSS by putting it after the Foundation CSS.

In the HTML I removed the left or right class.

The above can break the mobile version. To fix this place this CSS below the above CSS:

@media only screen and (max-width: 58.75em) { /* TopBar Breakpoint */
.top-bar-section ul {display: inline; margin: 0;}
}

Also the classes may change depending on the version of Foundation requiring you to modify the CSS classes used above.

L84
  • 45,514
  • 58
  • 177
  • 257
  • @Switchfire - I have tried that without luck. Glad it worked for you though. => – L84 Oct 29 '13 at 17:54
  • put the code in your css file `@media only screen and (min-width: 58.75em) {` literally before the closing tag '}' then delete one of the nav sides, and delete the left or right class out of the last 'ul="left/right"' should work perfectly then. EDIT: delete `

    ` out of the title area.
    – Switchfire Oct 30 '13 at 09:23
  • @mattrepublic - It works for me and I am using v5.2.3 of Foundation. – L84 Jun 12 '14 at 17:50
  • @railrailrail - You should delete your other question/answer as you answer here is sufficient. – L84 Jun 15 '14 at 06:17
  • @Lynda I wanted to create that for SEO purposes so people googling for foundation 5 wouldn't have to hunt around (since my answer has no votes it might not be considered), I went ahead and deleted it. – blnc Jun 16 '14 at 03:15
  • Please see my answer below for how to center the zurb foundation top bar below and preserve the mobile top bar function without having to dive into media queries – blnc Jun 16 '14 at 03:23
  • @railrailrail - Your answer will still show up on search engines under this question as will this question show up under search engines. In fact, Googling `center topbar in Foundation 5` has this question as #3 in the search results. SO help page says: `The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place.` So far, in my experience, centering the topbar in Foundation is similar for versions 4+ (I never used 3 or below). If it changes in a future version update your answer. => – L84 Jun 16 '14 at 03:50
0

Here is the best solution I've found that works for all resize events. It centers the Foundation 5 Top-bar elements.

Do note the 'contain-to-grid' div class will keep the widths of the top-bar nav within the frameworks of the website yet will not actually center the nav elements.

The code below does.

SCSS:

nav.top-bar:not(.expanded) {
            text-align: center;
            section.top-bar-section { display: inline-block; }
                           }

HTML:

<div class="contain-to-grid">
    <nav class="top-bar" data-topbar>
        <ul class="title-area">
            <li class="name">
                <h1><a href="#"></a></h1>
            </li>
            <!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
            <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
        </ul>

        <section class="top-bar-section">
            <ul>
                <li><%= link_to 'LINK 1', root_path %></li>
                <li class="divider"></li>
                <li><%= link_to 'LINK2', link_path %></li>
                <li class="divider"></li>
                <li class="has-dropdown">
                    <%= link_to 'Dropping', "#" %>
                    <ul class="dropdown">
                        <li><label>Label:</label></li>
                        <li><%= link_to 'DROP 1', drop_path %></li>
                        <li class="divider"></li>
                        <li><%= link_to 'DROP 2', drop_path %></li>
                    </ul>
                </li>
            </ul>
        </section>
    </nav>
</div>
blnc
  • 4,384
  • 1
  • 28
  • 42
0

If i understand the question fine, i see lot of anwser explain that he need to change the css.

He can also use the class of Foundation : contain-to-grid

<div class="contain-to-grid">
  <nav class="top-bar" data-topbar>
    ...
  </nav>
</div>

Live exemple : http://jsfiddle.net/gRtrX/37/ (size up to see the result)

It really look like

+-Parent container------------------------------------------------------------------+
|                                                                                   |
+-.top-bar--------------------------------------------------------------------------+
|              +-top-bar-section-+--------+--------+--------+--------+              |
|              |  Item  |  Item  |  Item  |  Item  |  Item  |  Item  |              |
|              |  menu  |  menu  |  menu  |  menu  |  menu  |  menu  |              |
|              |   01   |   02   |   03   |   04   |   05   |   06   |              |
|              +-top-bar-section-+--------+--------+--------+--------+              |
+-.top-bar--------------------------------------------------------------------------+
|                                                                                   |
|                                                                                   |
˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜
mpgn
  • 7,121
  • 9
  • 67
  • 100
  • 1
    While this works in some situations, if your menu is larger (wider) than the grid you will have more than one line of menu items. Also, depending on the menu items, you may want to center the menu within `contain-to-grid` vs. having excess space at the end. Again it depends on the situation. – L84 Jun 16 '14 at 03:52