1

I wonder how to change the layout of a JQuery UI menu from vertical to horizontal.

I have tried this but it only worked for main links on the menu bar but not the ones on the submenu.

I mean the items under 'Delphi' kept on displaying horizontally instead of dropping down vertically as these are sub items of Delphi:

<style>   
    .ui-menu:after {
        content: ".";
        display: block;
        clear: both;
        visibility: hidden;
        line-height: 0;
        height: 0;
    } 

    .ui-menu .ui-menu-item {
        display: inline-block;
        float: left;
        margin: 0;
        padding: 0;
        width: auto;
    }
</style>

                <nav>
                    <ul id="ui-menu" class="ui-menu">
                        <li><a href="#">Link one</a></li>
                        <li><a href="#">Link two</a></li>
                        <li><a href="#">Link three</a></li>
                        <li><a href="#">Link four</a></li>
                        <li>
                            <a href="#">Delphi</a>
                            <ul>
                                <li><a href="#">Ada</a></li>
                                <li><a href="#">Saarland</a></li>
                                <li><a href="#">Salzburg</a></li>
                            </ul>
                        </li>

                    </ul>
                </nav>


    $(function () {
        $("#ui-menu").menu();
    });

Edit

This is a screenshot of what I have achieved so far, and what still needs to be done:

enter image description here

Please let me know what I'm doing wrong.

Many thanks.

4

2 回答 2

0

工作示例http://jsfiddle.net/5a75Z/1/

.ui-menu li {
    float: left;
    padding: 0 6px;
    list-style: none;
}

我删除了你所有的 css 样式,然后只添加了上面的 3 种样式,现在它只使用float: left.,我只是添加了填充和列表样式。

编辑:

然后让子菜单垂直显示只需添加这个

ul ul {
    width: 100px;
    position: relative;
    left: -50px;
}

http://jsfiddle.net/5a75Z/2/

相应调整


编辑:

横向是这样 __ __ __
纵向是这样
|
|
|

垂直工作示例http://jsfiddle.net/5a75Z/3/

ul ul { 
    position: relative;
    width: 300px;
    padding-left: 50px;
}

li { list-style: none; }

ul ul li {
    float: left;
    padding: 0 5px;
    list-style: none;
    position: relative;
    top: -20px;
}
于 2014-02-08T23:06:19.853 回答
-1

我发现这个 CSS NAV Generator 可以解决这个问题(有点..):

http://cssmenumaker.com/builder/1444006

于 2014-02-09T12:27:52.830 回答