How to make jQuery UI nav menu horizontal?

后端 未结 11 1327
长发绾君心
长发绾君心 2020-12-02 15:29

I love the jQuery UI stuff!

I like the navigation menu, but I can\'t seem to get it horizontal. I\'ve got to be missing something that\'s a cinch.

Anyone kno

11条回答
  •  無奈伤痛
    2020-12-02 16:04

    I admire all these efforts to convert a menu to a menubar because I detest trying to hack CSS. It just feels like I'm meddling with powers I can't possibly ever understand! I think it's much easier to add the menubar files available at the menubar branch of jquery ui.

    I downloaded the full jquery ui css bundled file from the jquery ui download site

    In the head of my document I put the jquery ui css file that contains everything (I'm on version 1.9.x at the moment) followed by the specific CSS file for the menubar widget downloaded from the menubar branch of jquery ui

    
    
    

    Don't forget the images folder with all the little icons used by jQuery UI needs to be in the same folder as the jquery-ui.css file.

    Then at the end the body I have:

    
    
    
    

    That's a copy of an up-to-date version of jQuery, followed by a copy of the jQuery UI file, then the menubar module downloaded from the menubar branch of jquery ui

    The menubar CSS file is refreshingly short:

    .ui-menubar { list-style: none; margin: 0; padding-left: 0; }
    .ui-menubar-item { float: left; }
    .ui-menubar .ui-button { float: left; font-weight: normal; border-top-width: 0 !important; border-bottom-width: 0 !important; margin: 0; outline: none; }
    .ui-menubar .ui-menubar-link { border-right: 1px dashed transparent; border-left: 1px dashed transparent; }
    .ui-menubar .ui-menu { width: 200px; position: absolute; z-index: 9999; font-weight: normal; }
    

    but the menubar JavaScript file is 328 lines - too long to quote here. With it, you can simply call menubar() like this example:

    $("#menu").menubar({
        autoExpand: true,
        menuIcon: true,
        buttons: true,
        select: select
    });
    

    As I said, I admire all the attempts to hack the menu object to turn it into a horizontal bar, but I found all of them lacked some standard feature of a horizontal menu bar. I'm not sure why this widget is not bundled with jQuery UI yet, but presumably there are still some bugs to iron out. For instance, I tried it in IE 7 Quirks Mode and the positioning was strange, but it looks great in Firefox, Safari and IE 8+.

提交回复
热议问题