2017-08-16 55 views
3

我試圖用bootstrap4beta和dropdown-menu構建一個垂直菜單。我希望下拉菜單顯示在右側。但與dropdown-menu-right我只能讓它出現在下一行,而不是相同的。怎麼做?如何使此下拉菜單與其父項顯示在同一行上?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/> 
 

 
<nav class="nav flex-column col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4"> 
 
    <a class="nav-link active backgroundnav" href="#">HTML</a> 
 
    <a class="nav-link backgroundnav" href="#">CSS</a> 
 
    <a class="nav-link backgroundnav" href="#">JavaScript</a> 
 
    <li class="nav-item dropdown"> 
 
    <a class="nav-link dropdown-toggle backgroundnav" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false"> 
 
    Preview 
 
    </a> 
 
    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="Preview"> 
 
     <a class="dropdown-item" href="#">Mobile Phone</a> 
 
     <a class="dropdown-item" href="#">Tablet</a> 
 
     <a class="dropdown-item" href="#">Laptop</a> 
 
     <a class="dropdown-item" href="#">Desktop</a> 
 
    </div> 
 
    </li> 
 
</nav>

感謝。

回答

0

Bootstrap 4 popper.js正在定位下拉菜單,因此定製定位並不容易。你可以用這樣的CSS覆蓋,但棘手的部分是根據下拉鍊接的寬度來計算「65%」值。

.dropdown-menu-side { 
    transform: translateX(65%) !important; 
} 

https://www.codeply.com/go/BI2Gs7viID