中心多级下拉列表

时间:2017-05-18 22:11:31

标签: html dropdown

我的工作方式几乎是我想要的,除了下拉框值在左边,其余的正确居中。请帮助!

我希望将2级vales保留在插入符号的右侧,并且我已经尝试了我可以在网上找到的每一个标记。我画了一个空白。



$(document).ready(function(){
  $('.dropdown-submenu a.test').on("click", function(e){
    $(this).next('ul').toggle();
    e.stopPropagation();
    e.preventDefault();
  });
});

.dropdown-submenu {
    position: relative;
}

.dropdown-submenu .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -1px;

}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><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="container">
  <div class="dropdown">
    <button class="btn btn-default dropdown-toggle center-block" type="button" data-toggle="dropdown">Pick One
    <span class="caret"></span></button>
    <ul class="dropdown-menu">

      <li><a tabindex="-1">January</a></li>
      <li class="dropdown-submenu">
        <a class="test" tabindex="-1" href="#">Februrary <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a tabindex="-1" href="http://www.amazon.com/" target="_blank">Link</a></li>
        </ul>
      </li>
      <li><a tabindex="-1">March</a></li>
      <li><a tabindex="-1">April</a></li>     
      <li class="dropdown-submenu">
        <a class="test" tabindex="-1" href="#">May <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a tabindex="-1" href="http://www.amazon.com/" target="_blank">link</a></li>
        </ul>
      </li>
      <li><a tabindex="-1">June</a></li>      
      <li class="dropdown-submenu">
        <a class="test" tabindex="-1" href="#">July<span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a tabindex="-1" href="http://www.amazon.com/" target="_blank">link</a></li>
        </ul>
      </li>
    </ul>
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您只需要修改dropdowncontainer div:

  1. dropdown需要将其内容集中在其中
  2. 应更改display <div class="container" style="text-align: center;"> <div class="dropdown open" style="display: inline-block;"> .... </div> </div> ,以便它不会自动占用其容器内的所有宽度。
  3. 以下是一个例子:

    DateFormat format = new SimpleDateFormat("M-dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    
    days = new String[7];
    for (int i = 0; i < 7; i++)
    {
        days[i] = format.format(calendar.getTime());
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }