[英]How can I make this dropdown menu appear on the same line as its parent?
I'm trying to build a vertical menu with bootstrap4beta and dropdown-menu
. 我正在尝试使用bootstrap4beta和
dropdown-menu
构建一个垂直dropdown-menu
。 I want the dropdown to appear on the right. 我希望下拉列表显示在右侧。 But with
dropdown-menu-right
I can only make it appear in the next line and not on the same. 但是使用
dropdown-menu-right
我只能让它出现在下一行而不是相同。 How to do that? 怎么做?
<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>
Thanks. 谢谢。
Bootstrap 4 popper.js
is positioning the dropdown so it's not easy to customize the positioning. Bootstrap 4
popper.js
正在定位下拉列表,因此定制定位并不容易。 You could override with some CSS like this, but the tricky part is figuring the "65%" value which is based on the width of the dropdown link. 您可以使用这样的一些CSS覆盖,但棘手的部分是计算“65%”值,该值基于下拉链接的宽度。
.dropdown-menu-side {
transform: translateX(65%) !important;
}
https://www.codeply.com/go/BI2Gs7viID https://www.codeply.com/go/BI2Gs7viID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.