2016-06-22 77 views
0

在菜單1懸停的以下代碼中,我想顯示子菜單,但它不起作用。我在css以下申請。請修改我錯誤的代碼。繪畫子菜單中的問題

HTML

<div class="primary_nav_wrap"> 
     <ul> 
      <li class="current-menu-item"><a href="#">Home</a></li> 
      <li> 
       <a href="#">Menu 1</a> 
       <div class="sub_divsavedfun" id="Functions_1-5"> 
        <ul> 
         <li><a href="#">Sub Menu 1</a></li> 
         <li><a href="#">Sub Menu 2</a></li> 
         <li><a href="#">Sub Menu 3</a></li> 
         <li> 
          <a href="#">Sub Menu 4</a> 
          <ul> 
           <li> 
            <a href="#">Deep Menu 1</a> 
            <ul> 
             <li><a href="#">Sub Deep 1</a></li> 
             <li><a href="#">Sub Deep 2</a></li> 
             <li><a href="#">Sub Deep 3</a></li> 
             <li><a href="#">Sub Deep 4</a></li> 
            </ul> 
           </li> 
           <li><a href="#">Deep Menu 2</a></li> 
          </ul> 
         </li> 
         <li><a href="#">Sub Menu 5</a></li> 
        </ul> 
       </div> 
      </li> 
     </ul> 
    </div> 

CSS

<style> 
     .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 
} 
    </style> 

如果我刪除<div class="sub_divsavedfun" id="Functions_1-5">那麼它將work.But按規定,我有加div標籤。

回答

1

在CSS中添加這和它的正常工作

你的子ul所以前加DIV,CSS中.primary_nav_wrap ul li:hover > ul沒有發現任何ul。因爲HTML元素的結構現在是.primary_nav_wrap ul > li > div > ul

.primary_nav_wrap ul li:hover > div > ul 
{ 
    display:block 
} 

入住這Demo

1

你有divliul直接孩子。因此,只要更換下面的代碼:

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

到:

.primary_nav_wrap ul li:hover div > ul, .primary_nav_wrap ul li:hover > ul { 
    display: block 
} 

工作段:

.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% 
 
} 
 
/* CODE REPLACED BY BELOW 
 
.primary_nav_wrap ul li:hover > ul { 
 
    display: block 
 
} 
 
*/ 
 

 
/*Code added */ 
 
.primary_nav_wrap ul li:hover div > ul, .primary_nav_wrap ul li:hover > ul { 
 
    display: block 
 
}
<div class="primary_nav_wrap"> 
 
    <ul> 
 
    <li class="current-menu-item"><a href="#">Home</a> 
 
    </li> 
 
    <li> 
 
     <a href="#">Menu 1</a> 
 
     <div class="sub_divsavedfun" id="Functions_1-5"> 
 
     <ul> 
 
      <li><a href="#">Sub Menu 1</a> 
 
      </li> 
 
      <li><a href="#">Sub Menu 2</a> 
 
      </li> 
 
      <li><a href="#">Sub Menu 3</a> 
 
      </li> 
 
      <li> 
 
      <a href="#">Sub Menu 4</a> 
 
      <ul> 
 
       <li> 
 
       <a href="#">Deep Menu 1</a> 
 
       <ul> 
 
        <li><a href="#">Sub Deep 1</a> 
 
        </li> 
 
        <li><a href="#">Sub Deep 2</a> 
 
        </li> 
 
        <li><a href="#">Sub Deep 3</a> 
 
        </li> 
 
        <li><a href="#">Sub Deep 4</a> 
 
        </li> 
 
       </ul> 
 
       </li> 
 
       <li><a href="#">Deep Menu 2</a> 
 
       </li> 
 
      </ul> 
 
      </li> 
 
      <li><a href="#">Sub Menu 5</a> 
 
      </li> 
 
     </ul> 
 
     </div> 
 
    </li> 
 
    </ul> 
 
</div>