如何在垂直导航栏中创建下拉列表

时间:2019-05-29 07:51:35

标签: css3 bootstrap-4

我正在尝试在垂直导航栏中创建一个下拉列表。如果您能帮助我提出如何创建下拉列表的想法,我将不胜感激。

我尝试研究并为我的项目寻找不同的代码。这是我在代码中尝试过的一些东西。

Solutions I Tried

我的HTML代码:

            <div class="menu-overlay"></div>
                <div class="side-menu-wrapper">
                   <a href="#" class="menu-close">×</a>
                   <ul>
                      <li>
                          <form class="example"action="action_page.php">
                              <input type="text" placeholder="Search.." 
                              name="search">
                             <button type="submit">
                                   <i class="fa fa-search"></i>
                             </button>
                           </form>
                       </li>
                       <li>
                          <a href="Index.html" target="_blank" 
                           rel="nofollow">
                                Home
                           </a>
                       </li>
                       <li >
                          <a href="#" target="_blank" rel="nofollow">
                               About
                          </a>
                         <ul>
                            <li href="#" target="_blank" rel="nofollow">
                                <a >Introduction</a>
                            </li>
                            <li href="#" target="_blank" rel="nofollow"> 
                                <a >Mission</a>
                            </li>
                            <li href="#" target="_blank" rel="nofollow"> 
                                 <a >Vision</a>
                            </li>
                         </ul>
                     </li>
                     <li>
                        <a href="#" target="_blank" rel="nofollow">
                            Facebook
                        </a>
                     </li>
                     <li>
                       <a href="#" target="_blank" 
                       rel="nofollow">
                            Flickr
                        </a>
                   </li>
                </ul>
           </div>

我的CSS代码:

.side-menu-wrapper {
   background: rgba(0,114,187,0.7);
   padding: 40px 0 0 40px;
   position: fixed;
   top: 0;
   right: 0; 
   height: 100%;
   z-index: 2;
   transition: 0.5s;
   width: 250px;
   font: 20px "Courier New", Courier, monospace;
   box-sizing: border-box;
 }

.side-menu-wrapper > ul{
   list-style:none;
   padding:0;
   margin:0;
   overflow-y: auto;
   height:95%;
}

.side-menu-wrapper > ul > li > a {
    display: block;
    border-bottom: 1px solid black;
    padding: 6px 4px 6px 4px;
    color: white;
    transition: 0.3s;
    text-decoration: none;
  }

.side-menu-wrapper > a.menu-close { 
   padding: 8px 0 4px 23px;
   color: white;
   display: block;
   margin: -30px 0 -10px -20px;
   font-size: 35px;    
   text-decoration: none;
 }

.menu-overlay { 
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: rgba(0,0,0,.7);
  overflow-y: auto;
  overflow-x: hidden;
  text-align: center;
  opacity: 0;
  transition: opacity 1s;
}

结果: My Result

Thx Btw

1 个答案:

答案 0 :(得分:0)

通过使用引导程序的About类(more infos here)包装collapse子菜单,这应该可以工作:

<a href="#" class="active" data-toggle="collapse" data-target="#sub-menu" target="_blank" rel="nofollow">About<span class="ml-2" style="font-size: 12px;">&#x25BC;</span></a>
<div class="collapse" id="sub-menu">
    <ul>
        <li href="#" target="_blank" rel="nofollow">
            <a >Introduction</a>
        </li>
        <li href="#" target="_blank" rel="nofollow"> 
            <a >Mission</a>
        </li>
        <li href="#" target="_blank" rel="nofollow"> 
            <a >Vision</a>
        </li>
     </ul>
</div>

以下示例:

.side-menu-wrapper {
   background: rgba(0,114,187,0.7);
   padding: 40px 0 0 40px;
   position: fixed;
   top: 0;
   right: 0; 
   height: 100%;
   z-index: 2;
   transition: 0.5s;
   width: 250px;
   font: 20px "Courier New", Courier, monospace;
   box-sizing: border-box;
 }

.side-menu-wrapper > ul{
   list-style:none;
   padding:0;
   margin:0;
   overflow-y: auto;
   height:95%;
}

.side-menu-wrapper > ul > li > a {
    display: block;
    border-bottom: 1px solid black;
    padding: 6px 4px 6px 4px;
    color: white;
    transition: 0.3s;
    text-decoration: none;
  }

.side-menu-wrapper > a.menu-close { 
   padding: 8px 0 4px 23px;
   color: white;
   display: block;
   margin: -30px 0 -10px -20px;
   font-size: 35px;    
   text-decoration: none;
 }

.menu-overlay { 
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: rgba(0,0,0,.7);
  overflow-y: auto;
  overflow-x: hidden;
  text-align: center;
  opacity: 0;
  transition: opacity 1s;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

 <div class="menu-overlay "></div>
  <div class="side-menu-wrapper">
  <a href="#" class="menu-close">×</a>
    <ul>
    <li>
      <form class="example" action="action_page.php">
        <input type="text" placeholder="Search.." 
               name="search">
        <button type="submit">
          <i class="fa fa-search"></i>
        </button>
      </form>
      </li>
      <li>
        <a href="#" target="_blank" rel="nofollow">Home</a>
      </li>
      <li>
        <a href="#sub-menu" class="active" data-toggle="collapse" data-target="#sub-menu">About<span class="ml-2" style="font-size: 12px;">&#x25BC;</span></a>
        <div class="collapse" id="sub-menu">
          <ul>
            <li href="#" target="_blank" rel="nofollow">
              <a >Introduction</a>
            </li>
            <li href="#" target="_blank" rel="nofollow"> 
              <a >Mission</a>
            </li>
            <li href="#" target="_blank" rel="nofollow"> 
              <a >Vision</a>
            </li>
          </ul>
        </div>
      </li>
      <li>
        <a href="#" target="_blank" rel="nofollow">Facebook</a>
      </li>
      <li>
        <a href="#" target="_blank" rel="nofollow">Flickr</a>
      </li>
    </ul>
  </div>