2016-07-29 99 views
2

如何創建一個全寬下拉菜單(超級菜單)的菜單? 我試圖建立這樣的菜單example 我試圖利用語義UI彈出窗口,但這隻適用於第一個菜單項(錯誤:「Popup不適合在視口的邊界內)」。 我會喜歡一個解決方案,而不是使用下拉菜單,但它們不使用屏幕的整個寬度。語義UI全寬菜單下拉菜單

$('#menu1') 
 
    .popup({ 
 
    popup: '#menucontent1', 
 
    hoverable: true 
 
    }); 
 
    
 
    $('#menu2') 
 
    .popup({ 
 
    popup: '#menucontent2', 
 
    hoverable: true 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.js"></script> 
 
<div class="ui secondary pointing menu"> 
 
    <a class="browse item" id="menu1"> 
 
    Item 1</a> 
 
    <a class="browse item" id="menu2"> 
 
    Item 2</a> 
 
</div> 
 
<div class="ui fluid popup bottom left transition hidden" id="menucontent1"> 
 
    <div class="ui four column relaxed equal height divided grid"> 
 
    <div class="column"> 
 
     <h4 class="ui header">Fabrics</h4> 
 
     <div class="ui link list"> 
 
     <a class="item">Viscose</a> 
 
     </div> 
 
     <h4 class="ui header">Fabrics Level 2</h4> 
 
     <div class="ui link list"> 
 
     <a class="item">Cashmere</a> 
 
     <a class="item">Linen</a> 
 
     <a class="item">Cotton</a> 
 
     </div> 
 
    </div> 
 
    <div class="column"> 
 
     <h4 class="ui header">Size</h4> 
 
     <div class="ui link list"> 
 
     <a class="item">Small</a> 
 
     <a class="item">Medium</a> 
 
     <a class="item">Large</a> 
 
     <a class="item">Plus Sizes</a> 
 
     </div> 
 
    </div> 
 
    <div class="column"> 
 
     <h4 class="ui header">Colored</h4> 
 
     <div class="ui link list"> 
 
     <a class="item">Neutrals</a> 
 
     <a class="item">Brights</a> 
 
     <a class="item">Pastels</a> 
 
     </div> 
 
    </div> 
 
    <div class="column"> 
 
     <h4 class="ui header">Types</h4> 
 
     <div class="ui link list"> 
 
     <a class="item">Knitwear</a> 
 
     <a class="item">Outerwear</a> 
 
     <a class="item">Pants</a> 
 
     <a class="item">Shoes</a> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div> 
 
<div class="ui fluid popup bottom left transition hidden" id="menucontent2"> 
 
    <div class="ui four column relaxed equal height divided grid"> 
 
    <div class="column"> 
 
     <h4 class="ui header">Fabrics</h4> 
 
    </div> 
 
    <div class="column"> 
 
     
 
    </div> 
 
    <div class="column"> 
 
     
 
    </div> 
 
    <div class="column"> 
 
     
 
    </div> 
 
    </div> 
 
</div>

+1

我的解決方案基於[jsfiddle](https://jsfiddle.net/L20w60h0/3/)基礎關於@MarouenMhiris的回答。 – user3333137

回答

1

你不需要的jQuery的是,即使不使用Javascript: 我做了一個小搗鼓它:

<div class="ui secondary pointing menu"> 
    <ul class="menu"> 
     <li> 
      <a class="browse item" id="menu1" data-target="#menucontent1"> 
       Item 1</a> 
      <div class="popup" id="menucontent1"> 
       <div class="ui four column relaxed equal height divided grid"> 
        <div class="column"> 
         <h4 class="ui header">Fabrics</h4> 
         <div class="ui link list"> 
          <a class="item">Viscose</a> 
         </div> 
         <h4 class="ui header">Fabrics Level 2</h4> 
         <div class="ui link list"> 
          <a class="item">Cashmere</a> 
          <a class="item">Linen</a> 
          <a class="item">Cotton</a> 
         </div> 
        </div> 
        <div class="column"> 
         <h4 class="ui header">Size</h4> 
         <div class="ui link list"> 
          <a class="item">Small</a> 
          <a class="item">Medium</a> 
          <a class="item">Large</a> 
          <a class="item">Plus Sizes</a> 
         </div> 
        </div> 
        <div class="column"> 
         <h4 class="ui header">Colored</h4> 
         <div class="ui link list"> 
          <a class="item">Neutrals</a> 
          <a class="item">Brights</a> 
          <a class="item">Pastels</a> 
         </div> 
        </div> 
        <div class="column"> 
         <h4 class="ui header">Types</h4> 
         <div class="ui link list"> 
          <a class="item">Knitwear</a> 
          <a class="item">Outerwear</a> 
          <a class="item">Pants</a> 
          <a class="item">Shoes</a> 
         </div> 
        </div> 
       </div> 
      </div> 
     </li> 
     <li> 
      <a class="browse item" id="menu2" data-target="#menucontent2"> 
       Item 2</a> 
      <div class="popup" id="menucontent2"> 
       <div class="ui four column relaxed equal height divided grid"> 
        <div class="column"> 
         <h4 class="ui header">Fabrics</h4> 
        </div> 
        <div class="column"> 

        </div> 
        <div class="column"> 

        </div> 
        <div class="column"> 

        </div> 
       </div> 
      </div> 
     </li> 
    </ul> 
</div> 

和CSS:

.menu { 
    list-style: none; 
} 
.menu li { 
    float: left; 
    margin-right: 1em; 
} 
.popup { 
    background-color: #fff; 
    position: absolute; 
    border-radius: 5px; 
    border: 1px solid grey; 
    left: 0; 
    right: 0; 
    opacity: 0; 
    transition: opacity 0.5s ease; 
    padding: 1em; 
} 

.item:hover~div { 
    opacity: 1; 
} 
+0

謝謝。我覺得太複雜了。我想我會依靠javascript來改變活動類,並改變打開/關閉行爲(懸停/點擊),但你的回答給了我正確的方向。 – user3333137

+0

很高興我能幫忙:-) –