简体   繁体   English

如何在左侧栏中创建子菜单

[英]how to create sub menu in left side bar

i am new to HTML and i need to put some sub menus in my side bar.. just like a dropdown but it opens on the right side. 我是HTML的新手,我需要在边栏中添加一些子菜单。就像一个下拉菜单一样,但它会在右侧打开。 and how can i put links on it. 以及我该如何放置链接。 thanks 谢谢

html html

<ul>
    <li></br>
        <a class="active"  href="?">HOME</a>
    </li>
    <li></br>
        <a href="?">Manage Users</a> ----> needs the dropdown here
    </li>        
    <li></br>
        <a href="?">Manage Employees</a>----> needs the dropdown here
    </li>
    <li></br>
        <a href="?">Search</a>
    </li>
    <li></br>
        <a href="<?php echo site_url('login/logout') ?>">Log-Out</a>
    </li>
</ul>

here is my css. 这是我的CSS。

body {
    margin: 0;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 15%;
    background-color: #f1f1f1;
    position: fixed;
    height: 100%;
    overflow: auto;
}

li a {
    display: block;
    color: #000;
    padding: 8px 0 8px 16px;
    text-decoration: none;
}

li a.active {
    background-color: #4CAF50;
    color: white;
}

li a:hover:not(.active) {
    background-color: #555;
    color: white;
}

................................................................... ................................................... .................

<ul>
<li></br>
    <a class="active"  href="?">HOME</a>
</li>
<li></br>
    <a href="?">Manage Users</a> ----> needs the dropdown here
</li>        
<li></br>
    <a href="?">Manage Employees</a>---->
     <ul>
        <li><a href="#"> You put the sublists here</a></li> 
        <li> Many has you need</li>
     </ul>
</li>
<li></br>
    <a href="?">Search</a>
</li>
<li></br>
    <a href="<?php echo site_url('login/logout') ?>">Log-Out</a>
</li>

You don't need the </br> (correct would be <br/>, or <br>for HTML5). 您不需要</br>(正确的是<br/>或HTML5的<br>)。 I tried to make a simple solution with jQuery. 我试图用jQuery做一个简单的解决方案。 where you simply display or not the content you want. 您只显示或不显示所需内容的位置。

Hope it is what you were looking for. 希望这是您想要的。

 body { margin: 0; } ul { list-style-type: none; margin: 0; padding: 0; /*width: 15%;*/ background-color: #f1f1f1; /*position: fixed;*/ height: 100%; overflow: auto; } li a { display: block; color: #000; padding: 8px 0 8px 16px; text-decoration: none; } li a.active { background-color: #4CAF50; color: white; } li a:hover:not(.active) { background-color: #555; color: white; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li> <a class="active" href="#">HOME</a> </li> <li> <a href="#" onclick="$('ul#contentUsers').toggle();">Manage Users</a> <ul id="contentUsers" style="display: none;"> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> </ul> </li> <li> <a href="#" onclick="$('ul#contentEmployees').toggle();">Manage Employees</a> <ul id="contentEmployees" style="display: none;"> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> </ul> </li> <li> <a href="#">Search</a> </li> <li> <a href="#">Log-Out</a> </li> </ul> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM