create submenu with css

非 Y 不嫁゛ 提交于 2020-01-05 08:04:55

问题


Can someone help me. I have this html code and i want to design my submenus with css, but i am new in this and i really need a help

<div class="nav-collapse collapse">
            <ul id="nav-list" class="nav pull-right">
                <li><a href="#home">Home</a></li>
                <li><a href="#about">About</a></li>
                <li><a href="#updates">Updates</a></li>
                <li><a href="#screenshots">Screenshots</a></li>
                <li><a href="#howto">How to</a></li>
                    <ul>
                    <li><a href="#">Sub Item 1.1</a></li>
                    <li><a href="#">Sub Item 1.2</a></li>
                    </ul>
                <li><a href="#permissions">Permissions</a></li>
                <li><a href="#download">Download</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </div>

I want to have dropdown list for my submenus.My menu is horizontal at the moment


回答1:


To get you started...

.nav li ul { display: none; }

.nav li:hover ul { display: block;}

Your HTML needs a minor edit also... You need to nest the sub-menu <ul> inside the parent <li>. Like below:

<li><a href="#howto">How to</a>
    <ul>
        <li><a href="#">Sub Item 1.1</a></li>
        <li><a href="#">Sub Item 1.2</a></li>
    </ul>
</li>

Here is a jsfiddle demonstrating this working, obviously it is not horizontal as I lack the styles you already made, the functionality still works however when you hover the mouse over "How To":

http://jsfiddle.net/Zuvdf/



来源:https://stackoverflow.com/questions/15419345/create-submenu-with-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!