下拉按钮在引导程序中无法正常工作。有些人可以告诉我哪里出错了

时间:2014-05-20 10:01:13

标签: javascript html css twitter-bootstrap

我已经编写了一个小示例代码来测试bootstrap中的下拉按钮,但有些代码似乎没有按预期工作。有些人可以指出我错在哪里。

<div class = "col-md-8 col-xs-12">
        <h1>CuB</h1>
    <form class = "col-xs-8 form-horizontal" role = "form">
        <div class = "form-group">
            <label class = "col-sm-2 control-label">Latitude</label>
            <label class = "col-xs-8 control-label">xxx.xxxxx</label>
            <label class = "control-label col-sm-2">degrees</label>
        </div>
        <div class = "form-group">
            <label class = "col-sm-2 control-label">Display Units</label>
            <div class="col-sm-10">
                <button class = "btn navbar-btn btn-danger dropdown-toggle pull-right" data-toggle = "dropdown">DropDown<span class =  "caret"></span></button>
                    <ul class = "dropdown-menu">
                        <li>
                            <a href="#">Facebook</a>
                        </li>
                        <li>
                            <a href="#">Twitter</a>
                        </li>
                        <li>
                            <a href="#">Google+</a>
                        </li>
                        <li>
                            <a href="#">LinkedIn</a>
                        </li>
                    </ul>
            </div><!-- /.col-lg-6 -->
        </div>

        <div class = "form-group pager">
            <div class = "col-sm-3 col-xs-12">
                <button type = "button" class = "btn btn-success col-xs-12">Use</button>
            </div>
            </div>
            <div class = "col-sm-3 col-xs-12">
                <button type = "button" class = "btn btn-warning col-xs-12">Back</button>
            </div>
        </div>
    </form>
</div>

2 个答案:

答案 0 :(得分:1)

我完成了你的代码。我注意到了2个问题。

  1. col-sm-10下拉后缺少btn-group div

  2. 您必须将右拉类应用于父级而不是按钮。

  3. 这是一个小提琴演示。

    JS Fiddle Demo

    以下是HTML的结构。

    <div class = "col-md-8 col-xs-12">
            <h1>CuB</h1>
            <form class = "col-xs-8 form-horizontal" role = "form">
                <div class = "form-group">
                    <label class = "col-sm-2 control-label">Latitude</label>
                    <label class = "col-xs-8 control-label">xxx.xxxxx</label>
                    <label class = "control-label col-sm-2">degrees</label>
                </div>
                <div class = "form-group">
                    <label class = "col-sm-2 control-label">Display Units</label>
                    <div class="col-sm-10">
                        <div class="btn-group pull-right">
                            <button data-toggle="dropdown" class="btn btn-danger dropdown-toggle" type="button">
                                Dropdown <span class="caret"></span>
                            </button>
                            <ul role="menu" class="dropdown-menu">
                                <li>
                                    <a href="#">Facebook</a>
                                </li>
                                <li>
                                    <a href="#">Twitter</a>
                                </li>
                                <li>
                                    <a href="#">Google+</a>
                                </li>
                                <li>
                                    <a href="#">LinkedIn</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
    
                <div class = "form-group pager">
                    <div class = "col-sm-3 col-xs-12">
                        <button type = "button" class = "btn btn-success col-xs-12">
                            Use
                        </button>
                    </div>
                </div>
                <div class = "col-sm-3 col-xs-12">
                    <button type = "button" class = "btn btn-warning col-xs-12">
                        Back
                    </button>
                </div>
            </form>
        </div>
    

答案 1 :(得分:0)

你的问题来自右拉类,它在按钮上应用了一个浮点数。

您可以在菜单上应用此类来解决此问题:

 <div class="col-sm-10 dropdown">
     <button class = "btn navbar-btn btn-danger dropdown-toggle pull-right" data-toggle = "dropdown">DropDown<span class =  "caret"></span></button>
          <ul class = "dropdown-menu pull-right">
              <li>
                  <a href="#">Facebook</a>
              </li>
              <li>
                   <a href="#">Twitter</a>
               </li>
               <li>
                   <a href="#">Google+</a>
               </li>
               <li>
                   <a href="#">LinkedIn</a>
               </li>
           </ul>
      </div><!-- /.col-lg-6 -->
 </div>

Demo here