jquery - 增加 Bootstrap 下拉菜单宽度

标签 jquery html css twitter-bootstrap bootstrap-4

想知道是否有人有任何关于如何增加下拉宽度的提示?

我有一个包含两列的行,其中有一些 javascript,当被选中时可以上下滑动下拉菜单。我遇到的问题是我似乎无法弄清楚如何在选择时增加下拉列表宽度,理想情况下下拉列表将与列大小相匹配。但是发生的事情是下拉菜单宽度仅与下拉菜单中的文本大小相同,有人对如何增加下拉菜单宽度以匹配列大小有建议吗?

<div class="row question">
        <div class="dropdown">
            <div class="col-md-6" data-toggle="dropdown">
                First column
                <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                </ul>
            </div>
        </div><!-- end of the dropdown -->
        <div class="dropdown">
            <div class="col-md-6" data-toggle="dropdown">
                second column
                <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                    <li>Insert your menus here</li>
                </ul>
            </div>
        </div>
    </div><!--end of the row question -->

<script>
     // ADD SLIDEDOWN ANIMATION TO DROPDOWN //
    $('.dropdown').on('show.bs.dropdown', function(e){
        $(this).find('.dropdown-menu').first().stop(true, true).slideDown();
    });

    // ADD SLIDEUP ANIMATION TO DROPDOWN //
    $('.dropdown').on('hide.bs.dropdown', function(e){
        $(this).find('.dropdown-menu').first().stop(true, true).slideUp();
    });
</script>

最佳答案

2018 年更新

你应该能够像这样使用 CSS 来设置它..

.dropdown-menu {
  min-width:???px;
}

这适用于 Bootstrap 3 和 Bootstrap 4.0.0 (demo) .


Bootstrap 4 中的一个没有额外的 CSS 选项正在使用 sizing utils改变宽度。例如,此处 w-100 (width:100%) 类用于下拉菜单以填充其父项的宽度....

 <ul class="dropdown-menu w-100">
      <li><a class="nav-link" href="#">Choice1</a></li>
      <li><a class="nav-link" href="#">Choice2</a></li>
      <li><a class="nav-link" href="#">Choice3</a></li>
 </ul>

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

关于jquery - 增加 Bootstrap 下拉菜单宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23042182/

相关文章:

javascript - 应用于 html5 数字字段的 javascript 的错误行为

html - CSS 首字母高亮显示

jquery - Nivo Slider 导航样式化问题

html - 文本未包装在 flex 容器内

javascript - 按钮颜色不变

css - 两个 DIV 在 Mac 上的 Safari 5.1 中消失 - 从源代码中消失

html - 侧边栏高度不随内容高度一起变化

javascript - 无法在 Bootstrap 中实现模态

javascript - 获取元素编号或为其设置标识符

javascript - 使用 jQuery 从绝对路径的外部文件加载 HTML