gpt4 book ai didi

javascript - 最小化bootstrap 3下拉菜单的宽度

转载 作者:行者123 更新时间:2023-11-28 07:33:18 25 4
gpt4 key购买 nike

下面是我的代码片段,正如您在下拉菜单中看到的那样,它的宽度很大,所以我想让它的宽度等于父触发按钮的宽度,有人知道怎么做吗?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
test
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right downloadoptions">
<li role="presentation"><a class="tbcopy" role="menuitem" tabindex="-1" href="#">COPY</a></li>
<li role="presentation"><a class="tbpdf" role="menuitem" tabindex="-1" href="#">PDF</a></li>
<li role="presentation"><a class="tbcsv" role="menuitem" tabindex="-1" href="#">CSV</a></li>
<li role="presentation"><a class="tbexcel" role="menuitem" tabindex="-1" href="#">EXCEL</a></li>
<li role="presentation"><a class="tbprint" role="menuitem" tabindex="-1" href="#">PRINT</a></li>
</ul>
</div>

最佳答案

只需覆盖下拉菜单的默认 min-width:

.downloadoptions {
min-width: 0 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
test
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right downloadoptions">
<li role="presentation"><a class="tbcopy" role="menuitem" tabindex="-1" href="#">COPY</a>
</li>
<li role="presentation"><a class="tbpdf" role="menuitem" tabindex="-1" href="#">PDF</a>
</li>
<li role="presentation"><a class="tbcsv" role="menuitem" tabindex="-1" href="#">CSV</a>
</li>
<li role="presentation"><a class="tbexcel" role="menuitem" tabindex="-1" href="#">EXCEL</a>
</li>
<li role="presentation"><a class="tbprint" role="menuitem" tabindex="-1" href="#">PRINT</a>
</li>
</ul>
</div>

关于javascript - 最小化bootstrap 3下拉菜单的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31374490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com