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

时间:2021-07-02 17:17:14

I have written a small sample code to test the dropdown button in bootstrap, but some how it doesn't seem to work as expected. Can some body point out where i wen wrong.

我已经编写了一个小示例代码来测试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 个解决方案

#1


1  

I went throught your code. I noticed 2 issues.

我完成了你的代码。我发现了2个问题。

  1. Missing of btn-group div after col-sm-10 dropdown

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

  2. you must apply pull-right class to the parent instead of the button.

    您必须将pull-right类应用于父级而不是按钮。

Here is a fiddle demo.

这是一个小提琴演示。

JS Fiddle Demo

JS小提琴演示

Here is the structure of the HTML.

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

#2


0  

Your problem comes from the pull-right class, which apply a float:right on the button.

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

You can apply this class on the menu to fix this:

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

 <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

#1


1  

I went throught your code. I noticed 2 issues.

我完成了你的代码。我发现了2个问题。

  1. Missing of btn-group div after col-sm-10 dropdown

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

  2. you must apply pull-right class to the parent instead of the button.

    您必须将pull-right类应用于父级而不是按钮。

Here is a fiddle demo.

这是一个小提琴演示。

JS Fiddle Demo

JS小提琴演示

Here is the structure of the HTML.

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

#2


0  

Your problem comes from the pull-right class, which apply a float:right on the button.

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

You can apply this class on the menu to fix this:

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

 <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