2

I have a <p:menubar> with some <p:menuitem>s to display a horizontal menu to users. This is my current simplified code (removed internationalization and other non-related stuff):

<p:menubar id="mbrMainMenu" styleClass="centeredMenuBar">
    <p:menuitem value="Home" outcome="/index.xhtml" />
    <p:submenu label="Product Catalog">
        <!-- some menuitems here... -->
    </p:submenu>
    <p:submenu label="Make your own design">
        <!-- some menuitems here... -->
    </p:submenu>
</p:menubar>

Code above gets displayed like this:

 _____________________________________________________ _____________________________________
|        |                   |                        |                                     |
|  Home  |  Product Catalog  |  Make your own design  |         <wasted whitespace>         |
|________|___________________|________________________|_____________________________________|

I'm searching for a look n' feel where the <p:menuitem> and <p:submenu> are centered and the width of each one is distributed accordingly (I'm not very skilled with CSS):

 _______________________________________________________________________________
|                  |                           |                                |
|       Home       |      Product Catalog      |      Make your own design      |
|__________________|___________________________|________________________________|

I've found how to center them using a custom CSS centeredMenuBar (taken from here: How to centralize primefaces menubar?), but now I'm having a hard time trying to distribute the menu items along the menu bar, they are all stick.

 __________________________________________________________________ ____________
|            |        |                   |                        |            |
|  <wasted>  |  Home  |  Product Catalog  |  Make your own design  |  <wasted>  |
|____________|________|___________________|________________________|____________|

I've tried this but failed:

  1. Creating a custom CSS to override the ui-menu-item and ui-menu-parent PrimeFaces styles:

    .ui-menu-item .ui-menu-parent {
        width: auto;
    }
    
  2. Using style="width: auto;" directly in the <p:menuitem> and <p:submenu>.

Any idea how to accomplish this?


This is what I have:

enter image description here

This is what I want (last picture edited in paint just to show the last form):

enter image description here

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • To be sure: 1/ Do you want the whole bar to be full width or just the length of text plus some padding? 2/ Does "Home" and "Very long text" need to have equal width or "depends of the length of text + some fixed padding"? – FelipeAls Sep 21 '13 at 19:14
  • Something close can be realized using `inline-block`'s or `table-cell`, but getting the vertical separators mid-way between the text elements is hard to do unless you add some extra mark-up. What are you willing to consider? – Marc Audet Sep 21 '13 at 19:14
  • @FelipeAls 1/ I want to maintain the whole bar to be full width to the page. 2/ Currently, they have different width, I wish there is a way they could have same width and be distributed accordingly dynamically in case I need to add more options in the menu. By now, they are all distributed and centered but there's a big space of difference between the options and the Window Borders. – Luiggi Mendoza Sep 21 '13 at 19:18
  • @MarcAudet I have all the freedom to add and edit code as long as *it works* i.e. the clients and users see the UI and are comfortable. – Luiggi Mendoza Sep 21 '13 at 19:19
  • Would my previous answer about [css table-cell equal width](http://stackoverflow.com/questions/10525744/css-table-cell-equal-width/10526275#10526275) be a suitable solution then? The value of `table-layout` changes the algorithm used by browsers from "adapt to text" to "adapt to what author set" (and table layout - in CSS - will render items on a single row, same height "cells", very flexible whatever the number of "cells"). – FelipeAls Sep 21 '13 at 19:22
  • @FelipeAls I could give it a try, but unsure if it will work because the `` are displayed in form of `
  • ` rather than `
    `s.
  • – Luiggi Mendoza Sep 21 '13 at 19:32