使引导菜单3中的下拉菜单与右侧对齐

时间:2018-07-11 04:21:22

标签: html css twitter-bootstrap-3

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="group-menu-body">
  <div class="dropdown">
    <ul class="">
      <li class="">
        <a class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Logistics
        <span class="caret"></span>
      </a>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1" style="right: 0; left: auto;">
          <li><a href="#">Grant Office Supplies/Gift</a></li>
          <li><a href="#">Print Name Card</a></li>
          <li><a href="#">Photo/Notarization</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
        </ul>
      </li>
    </ul>
  </div>
</div>

我具有以下下拉菜单列表,但是下拉菜单内容如图片所示。因此,我想将其向右对齐。有没有办法对齐它?

示例:

enter image description here

谢谢。

2 个答案:

答案 0 :(得分:0)

您只需要向dropdown-menu-right元素添加dropdown-menu类。试试这个代码。

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="group-menu-body">
    <div class="dropdown">
    <ul class="">
      <li class="">
        <a class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Logistics
        <span class="caret"></span>
      </a>
        <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1" style="right: 0; left: auto;">
             <li><a href="#">Grant Office Supplies/Gift</a></li>
            <li><a href="#">Print Name Card</a></li>
            <li><a href="#">Photo/Notarization</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
        </ul>
      </li>    
    </ul>
  </div>
  </div>
</div>

答案 1 :(得分:0)

尝试一下:

.dropdown-menu {
    float:left;
}
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display: block; position: static; margin-bottom: 5px; *width: 180px;">
    <li><a tabindex="-1" href="#">Action</a></li>
    <li><a tabindex="-1" href="#">Another action</a></li>
    <li class="dropdown-submenu dropdown-menu-right"> <a tabindex="-1" href="#">More options</a>
        <ul class="dropdown-menu">
            <li><a tabindex="-1" href="#">Second level link</a></li>
            <li><a tabindex="-1" href="#">Second level link</a></li>
            <li><a tabindex="-1" href="#">Second level link</a></li>
            <li><a tabindex="-1" href="#">Second level link</a></li>
            <li><a tabindex="-1" href="#">Second level link</a></li>
        </ul>
    </li>
</ul>

演示链接: http://jsfiddle.net/szx4Y/2392/