2017-03-22 99 views
0

我很新,在這個。我有一個帶子菜單的疊加菜單,但是我需要子菜單的寬度小於菜單,每當我更改子菜單的寬度時,它會更改,但也會保留父菜單的寬度。子菜單的疊加菜單,需要改變子菜單的寬度

[這是子菜單的外觀1

HTML

`<div class="row"> 
     <div class="col-md-3"> 
      <ul class="menu"> 
       <li><a href="trucks.html" target="preview-iframe">Book Trucks</a></li> 
       <li class="active"> <a href="schedule.html" target="preview-iframe" data-toggle="collapse" data-target="#toggle1" class="collapsed">Schedule <i class="fa fa-angle-down" aria-hidden="true"></i> 
       </a> 
        <div class="collapse" id="toggle1"> 
         <ul class="menu-list"> 
          <li><a href="start.html" target="preview-iframe"> Start Date</a></li> 
          <li><a href="end.html" target="preview-iframe"> End Date</a></li> 
         </ul> 
       <li class="active"> <a href="routes.html" target="preview-iframe" data-toggle="collapse" data-target="#toggle" class="collapsed">Routes <i class="fa fa-angle-down" aria-hidden="true"></i> 
       </a> 
        <div class="collapse" id="toggle"> 
         <ul class="menu-list"> 
          <li><a href="routes2.html" target="preview-iframe">Route 2</a></li> 
          <li><a href="routes3.html" target="preview-iframe">Route 3</a></li> 
          <li><a href="routes4.html" target="preview-iframe">Route 4</a></li> 
          <li><a href="routes5.html" target="preview-iframe">Route 5</a></li> 
         </ul> 
        </div> 
       </li> 
       <li><a href="region.html" target="preview-iframe">Availability Regions</a></li> 
     </div>` 




CSS 
    /* MENU */ 
    @media (min-width: 768px) { 
     .menu { 
      width:72.5%; 
      left: 100px; 
      border: 1px solid #129cf3; 
      position: absolute; 
      background-color: #f2f2f2; 
      font: 18px 'Raleway', sans-serif; 
      text-align: center; 
      text-decoration: none; 
      border-collapse: collapse; 
      top: 250px; 
      font-weight: 600; 
      border-bottom: none; 
      transition: all 1s; 
      box-shadow: 10px 10px 5px #888888; 
     } 
     .menu li { 
      list-style: none; 
      text-decoration: none; 
     } 
    } 
    .menu a { 
     color: #000; 
     left: 800px; 
     text-transform: uppercase; 
     letter-spacing: .1em; 
     text-decoration: none; 
     display: block; 
     padding: 35px; 
     border-bottom: 1px solid #129cf3; 
     text-align: center; 
     border-collapse: collapse; 
     transition: all 1s; 
    } 
    .menu a:hover { 
     background-color: #129cf3; 
     color: #000; 
     text-decoration: none; 
    } 
    .menu i { 
     font-weight: 600; 
    } 

    #toggle,menu:before 
    #toggle:after{ 
     width 50%; 
    } 

    .menu-list li a{ 
     margin-left: 20px; 
     margin-right: 20px; 
     margin-bottom:0px; 
     margin-top: 0px; 
     padding: 15px; 
     border: 0px; 
     font-size: 12px; 
     text-align: center; 
    } 

https://jsfiddle.net/cnezagf0/

回答

0

這將是CSS /* MENU */

ul{ 

     list-style:none; 
     padding:0;margin:0; 
    } 
    @media (min-width: 768px) { 
     .menu { 
      width:72.5%; 
      left: 100px; 
      border: 1px solid #129cf3; 
      position: relatve; 
      background-color: #f2f2f2; 
      font: 18px 'Raleway', sans-serif; 
      text-align: center; 
      text-decoration: none; 
      border-collapse: collapse; 
      top: 250px; 
      font-weight: 600; 
      border-bottom: none; 
      transition: all 1s; 
      box-shadow: 10px 10px 5px #888888; 
     } 
     .menu>li { 
      list-style: none; 
      text-decoration: none; 
     } 
    } 
    .menu >li>a { 
     color: #000; 
     left: 800px; 
     text-transform: uppercase; 
     letter-spacing: .1em; 
     text-decoration: none; 
     display: block; 
     padding: 35px; 
     border-bottom: 1px solid #129cf3; 
     text-align: center; 
     border-collapse: collapse; 
     transition: all 1s; 
    } 
    .menu >li> a:hover { 
     background-color: #129cf3; 
     color: #000; 
     text-decoration: none; 
    } 
    .menu i { 
     font-weight: 600; 
    } 

    #toggle,menu:before 
    #toggle:after{ 
     width 50%; 
    } 

    .menu-list >li >a{ 
    margin: 0 auto; 
    padding: 15px; 
    border: 0px; 
    font-size: 12px; 
    text-align: center; 
    color: #000; 
    text-transform: uppercase; 
    letter-spacing: .1em; 
    text-decoration: none; 
    text-align: center; 
    width: 80%; 
    background: red; 
    display: block; 

    } 

和提琴手鍊接https://jsfiddle.net/zsL2d92y/1/

+0

您好,感謝您的幫助,我想從子菜單 –

+0

.menu-list> li> a {}這個子菜單中刪除主菜單填充,您可以將填充更改爲您的要求 –