2015-09-04 35 views
1

如何使子菜單與它的父級菜單與此css處於同一水平?

* { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
body { 
 
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 
 
} 
 
a { 
 
    text-decoration: none; 
 
    font-size: 11px; 
 
    font-weight: 100; 
 
    width: 100%; 
 
    box-sizing: border-box; 
 
} 
 
ul { 
 
    list-style: none; 
 
} 
 
/* 
 
LEVEL ONE : MAIN MENU 
 
*/ 
 

 
ul.dropdown { 
 
    position: relative; 
 
} 
 
ul.dropdown li.menuppal { 
 
    float: left; 
 
    zoom: 1; 
 
    background: #B2DAFB repeat-x top left; 
 
    -moz-border-radius: 5px; 
 
    -webkit-border-radius: 5px; 
 
    border-left: 1px solid #222; 
 
} 
 
ul.dropdown li.menuppal a { 
 
    display: block; 
 
    padding: 4px 8px; 
 
    color: #000000; 
 
} 
 
/* Doesn't work in IE */ 
 

 
ul.dropdown li.menuppal:hover { 
 
    background: #ccc url('../images/menuDark.png') repeat-x 50% 50%; 
 
    position: relative; 
 
} 
 
/* 
 
     FIN LEVEL ONE 
 
*/ 
 

 
/* 
 
LEVEL TWO 
 
*/ 
 

 
ul.dropdown ul { 
 
    width: 220px; 
 
    visibility: hidden; 
 
    position: absolute; 
 
    top: 100%; 
 
    left: 0; 
 
    background-color: #40617C; 
 
} 
 
ul.dropdown ul li { 
 
    float: none; 
 
} 
 
/* IE 6 & 7 Needs Inline Block */ 
 

 
ul.dropdown li.menuppal ul li a { 
 
    border-right: none; 
 
    color: #FFF; 
 
    display: inline-block; 
 
} 
 
ul.dropdown li.menuppal ul li a:hover { 
 
    background: #07243a; 
 
} 
 
ul.dropdown li.menuppal ul li a:visited { 
 
    word-break: break-all; 
 
} 
 
/* 
 
LEVEL THREE 
 
*/ 
 

 
ul.dropdown ul ul { 
 
    left: 100%; 
 
} 
 
ul.dropdown li:hover > ul { 
 
    visibility: visible; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://iscriptdesign.googlecode.com/svn-history/r2/trunk/js/jquery.dropdownPlain.js"></script> 
 

 
<div> 
 
    <ul class="dropdown"> 
 
    <li class="menuppal"><a href="#">Administration</a> 
 
     <ul> 
 
     <li><a href="#">Artificial Turf</a> 
 
     </li> 
 
     <li> 
 
      <a href="#">Batting Cages</a> 
 
      <ul> 
 
      <li><a href="#">Indoor</a> 
 
      </li> 
 
      <li><a href="#">Outdoor</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li><a href="#">Benches &amp; Bleachers</a> 
 
     </li> 
 
     <li><a href="#">Communication Devices</a> 
 
     </li> 
 
     <li><a href="#">Dugouts</a> 
 
     </li> 
 
     <li><a href="#">Fencing &amp; Windscreen</a> 
 
     </li> 
 
     <li><a href="#">Floor Protectors</a> 
 
     </li> 
 
     <li><a href="#">Foul Poles</a> 
 
     </li> 
 
     <li><a href="#">Netting</a> 
 
     </li> 
 
     <li><a href="#">Outdoor Furniture</a> 
 
     </li> 
 
     <li><a href="#">Outdoor Signs</a> 
 
     </li> 
 
     <li><a href="#">Padding</a> 
 
     </li> 
 
     <li><a href="#">Scoreboards</a> 
 
     </li> 
 
     <li><a href="#">Shade Structures</a> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    <li class="menuppal"><a href="#">Structure</a> 
 
     <ul> 
 
     <li><a href="#">All-in-One Team Cart</a> 
 
     </li> 
 
     <li><a href="#">Air &amp; Electrical Reels</a> 
 
     </li> 
 
     <li><a href="#">Field Drags</a> 
 
     </li> 
 
     <li> 
 
      <a href="#">Field Marking Equipment</a> 
 
      <ul> 
 
      <li><a href="#">Batter's Box Templates</a> 
 
      </li> 
 
      <li><a href="#">Dryline Markers</a> 
 
      </li> 
 
      <li><a href="#">Field Paint</a> 
 
      </li> 
 
      <li><a href="#">Field Sprayers</a> 
 
      </li> 
 
      <li><a href="#">Stencils</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li> 
 
      <a href="#">Field Tarps</a> 
 
      <ul> 
 
      <li><a href="#">Area Tarps</a> 
 
      </li> 
 
      <li><a href="#">Growth Covers/Protectors</a> 
 
      </li> 
 
      <li><a href="#">Infield Tarps</a> 
 
      </li> 
 
      <li><a href="#">Tarp Accessories</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li><a href="#">Hand Tools</a> 
 
     </li> 
 
     <li> 
 
      <a href="#">Irrigation, Hoses, Nozzles</a> 
 
      <ul> 
 
      <li><a href="#">Hoses &amp; Hose Reels</a> 
 
      </li> 
 
      <li><a href="#">Irrigation</a> 
 
      </li> 
 
      <li><a href="#">Nozzles</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li><a href="#">Layout Tools</a> 
 
     </li> 
 
     <li><a href="#">Moisture Removal</a> 
 
     </li> 
 
     <li><a href="#">Mound Fortification</a> 
 
     </li> 
 
     <li><a href="#">Mowers &amp; Stripers</a> 
 
     </li> 
 
     <li><a href="#">Soil Management</a> 
 
     </li> 
 
     <li><a href="#">Soil Amendments</a> 
 
     </li> 
 
     <li><a href="#">Spreaders &amp; Sweepers</a> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    <li class="menuppal"><a href="#">Exercice</a> 
 
     <ul> 
 
     <li> 
 
      <a href="#">Baseball - Softball</a> 
 
      <ul> 
 
      <li><a href="#">Base Accessories</a> 
 
      </li> 
 
      <li><a href="#">Bases &amp; Home Plates</a> 
 
      </li> 
 
      <li><a href="#">Game Accessories</a> 
 
      </li> 
 
      <li><a href="#">Pitching Rubbers</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li> 
 
      <a href="#">Batting Practice Equipment</a> 
 
      <ul> 
 
      <li><a href="#">Backstops</a> 
 
      </li> 
 
      <li><a href="#">Infield Screens</a> 
 
      </li> 
 
      <li><a href="#">Jugs Pitching Machines</a> 
 
      </li> 
 
      <li><a href="#">Turf Mats</a> 
 
      </li> 
 
      <li><a href="#">Turf Protectors</a> 
 
      </li> 
 
      <li><a href="#">Replacement Accessories</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li> 
 
      <a href="#">Batting Cages</a> 
 
      <ul> 
 
      <li><a href="#">Indoor</a> 
 
      </li> 
 
      <li><a href="#">Outdoor</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li> 
 
      <a href="#">Portable Mounds</a> 
 
      <ul> 
 
      <li><a href="#">Batting Practice Mounds</a> 
 
      </li> 
 
      <li><a href="#">Game Mounds</a> 
 
      </li> 
 
      <li><a href="#">Practice Mounds</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li> 
 
      <a href="#">Football</a> 
 
      <ul> 
 
      <li><a href="#">First Down Markers</a> 
 
      </li> 
 
      <li><a href="#">Football Accessories</a> 
 
      </li> 
 
      <li><a href="#">Football Goalposts</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li> 
 
      <a href="#">Soccer</a> 
 
      <ul> 
 
      <li><a href="#">Soccer Goals</a> 
 
      </li> 
 
      <li><a href="#">Soccer Accessories</a> 
 
      </li> 
 
      </ul> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    <li class="menuppal"><a href="#">Contribuables et biens</a> 
 
     <ul> 
 
     <li><a href="#">Ladders &amp; Sticks</a> 
 
     </li> 
 
     <li><a href="#">Hurdles</a> 
 
     </li> 
 
     <li><a href="#">Training Accessories</a> 
 
     </li> 
 
     <li><a href="#">Smart-Cart Training System</a> 
 
     </li> 
 
     <li><a href="#">Smart-Hurdle Collection</a> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    <li class="menuppal"><a href="#">Recettes</a> 
 
     <ul> 
 
     <li><a href="#">Field Design</a> 
 
     </li> 
 
     <li><a href="#">Turf Management</a> 
 
     </li> 
 
     <li><a href="#">Training</a> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    <li class="menuppal"><a href="#">Edition</a> 
 
     <ul> 
 
     <li><a href="#">Field Design</a> 
 
     </li> 
 
     <li><a href="#">Turf Management</a> 
 
     </li> 
 
     <li><a href="#">Training</a> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    <li class="menuppal"><a href="#">Outils</a> 
 
     <ul> 
 
     <li><a href="#">Field Design</a> 
 
     </li> 
 
     <li><a href="#">Turf Management</a> 
 
     </li> 
 
     <li><a href="#">Training</a> 
 
     </li> 
 
     <li><a href="#"> - VIEW ALL - </a> 
 
     </li> 
 
     </ul> 
 
    </li> 
 
    </ul> 
 
</div>

我想打一個下拉菜單:

在運行時,子菜單是不是在同一水平其父:

enter image description here

那麼如何修理它 ?

回答

1

複製下面的CSS:

* { 
    margin: 0; 
    padding: 0; 
} 

body { 
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; 
} 

a { 
    text-decoration: none; 
    font-size: 11px; 
    font-weight: 100; 
    width: 100%; 
    box-sizing: border-box; 
} 

ul { 
    list-style: none; 
} 

/* 
LEVEL ONE : MAIN MENU 
*/ 
ul.dropdown { 
    position: relative; 
} 

ul.dropdown li.menuppal { 
    float: left; 
    zoom: 1; 
    background: #000 url(../images/menuLight.png) repeat-x top left; 
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px; 
    border-left: 1px solid #222; 
} 

ul.dropdown li.menuppal a { 
    display: block; 
    padding: 4px 8px; 
    color: #000000; 
} 

/* Doesn't work in IE */ 
ul.dropdown li.menuppal:hover { 
    background: #ccc url('../images/menuDark.png') repeat-x 50% 50%; 
    position: relative; 
} 
/* 
     FIN LEVEL ONE 
*/ 

/* 
LEVEL TWO 
*/ 
ul.dropdown ul { 
    width: 220px; 
    visibility: hidden; 
    position: absolute; 
    top: 100%; 
    left: 0; 
    background-color: #40617C; 
} 





ul.dropdown ul li { 
    float: none; 
    position: relative; 
} 

/* IE 6 & 7 Needs Inline Block */ 
ul.dropdown li.menuppal ul li a { 
    border-right: none; 
    color: #FFF; 
    display: inline-block; 
} 

ul.dropdown li.menuppal ul li a:hover { 
    background: #07243a; 
} 

ul.dropdown li.menuppal ul li a:visited { 
    word-break: break-all; 
} 

/* 
LEVEL THREE 
*/ 
ul.dropdown ul ul { 
    left: 100%; 
    top:0!important 
} 

ul.dropdown li:hover > ul { 
    visibility: visible; 


} 
1

找到這些選擇器並在其中添加此CSS屬性,然後它將打開其父鏈接前面的每個子菜單。

ul.dropdown ul li {position:relative} 
    ul.dropdown ul {top:0} 
    .dropdown>li>ul {top: 20px;} 
+1

2級菜單隱藏1級菜單! – pheromix

+0

@pheromix我已經添加了一行代碼,它會修復你的第一級隱藏。對不起,我錯過了 –

0

你可以試試這個link。這裏的開發商已經表示,它可能會造成問題,但它並沒有當我試圖

#primary_nav_wrap 
{ 
    margin-top:15px 
} 

#primary_nav_wrap ul 
{ 
    list-style:none; 
    position:relative; 
    float:left; 
    margin:0; 
    padding:0 
} 

#primary_nav_wrap ul a 
{ 
    display:block; 
    color:#333; 
    text-decoration:none; 
    font-weight:700; 
    font-size:12px; 
    line-height:32px; 
    padding:0 15px; 
    font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif 
} 

#primary_nav_wrap ul li 
{ 
    position:relative; 
    float:left; 
    margin:0; 
    padding:0 
} 

#primary_nav_wrap ul li.current-menu-item 
{ 
    background:#ddd 
} 

#primary_nav_wrap ul li:hover 
{ 
    background:#f6f6f6 
} 

#primary_nav_wrap ul ul 
{ 
    display:none; 
    position:absolute; 
    top:100%; 
    left:0; 
    background:#fff; 
    padding:0 
} 

#primary_nav_wrap ul ul li 
{ 
    float:none; 
    width:200px 
} 

#primary_nav_wrap ul ul a 
{ 
    line-height:120%; 
    padding:10px 15px 
} 

#primary_nav_wrap ul ul ul 
{ 
    top:0; 
    left:100% 
} 

#primary_nav_wrap ul li:hover > ul 
{ 
    display:block 
} 

但你需要構建它進一步根據您的需要。