尽量减少bootstrap 3下拉菜单的宽度

时间:2015-07-13 02:04:15

标签: javascript jquery html css twitter-bootstrap-3

下面是我的片段,正如您在下拉菜单中看到的那样,它的宽度很大所以我想让它的宽度等于父触发按钮,任何人都知道如何制作它?

<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>

2 个答案:

答案 0 :(得分:0)

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

&#13;
&#13;
.downloadoptions {
    min-width: 0 !important;
}
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试此代码

dropdown-menu { 
 width: 69px;
  padding: 5px 0;
  margin: 2px 0 0;
  font-size: 13px;
  }