我有3个主要"类别"里面和每个"类别"有几个复选框(这用于过滤搜索)。 这是我的代码示例:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="col-3 dropdown">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown">Button</button>
<div class="dropdown-menu">
<div class="dropdown-item">
<div class="row">
<div class="col">
<h6>Category 1:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
<div class="col">
<h6>Category 2:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
<div class="col">
<h6>Category 3:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
&#13;
您可能已经注意到,下拉列div
也是col-3
。
基本上,我希望下拉菜单占用比col-3
更多的水平空间(就像text-nowrap
中div
所做的简单文字一样。)这里有一个例子我希望它看起来像:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="dropdown">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown">Button</button>
<div class="dropdown-menu">
<div class="dropdown-item">
<div class="row">
<div class="col">
<h6>Category 1:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
<div class="col">
<h6>Category 2:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
<div class="col">
<h6>Category 3:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
默认情况下,Bootstrap将position:relative
应用于.dropdown
类。如果您希望下拉列表的子元素超出下拉列表,则在下拉列表中添加一个类以覆盖position:relative
。在这里,我添加了.extended
类。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<style>
.extended {
position: initial !important;
}
</style>
<div class="col-3 dropdown extended">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown">Button</button>
<div class="dropdown-menu">
<div class="dropdown-item">
<div class="row">
<div class="col">
<h6>Category 1:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
<div class="col">
<h6>Category 2:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
<div class="col">
<h6>Category 3:</h6>
<ul class="list-group">
<li class="list-group-item"><a href="#"><input type="checkbox"> Option1</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option2</a></li>
<li class="list-group-item"><a href="#"><input type="checkbox"> Option3</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
&#13;