简体   繁体   English

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

[英]Dropdown button not working properly in bootstrap. Can some body tell me where i went wrong

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. 我编写了一个小的示例代码来测试Bootstrap中的下拉按钮,但是有些似乎不起作用。 Can some body point out where i wen wrong. 能不能指出我错了的地方。

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

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>

Your problem comes from the pull-right class, which apply a float:right on the button. 您的问题来自向右拉类,该类在按钮上应用了float:right。

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 在这里演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以告诉我哪里出错了吗? - Can someone please tell me where I went wrong? CSS-有人可以帮助我找出下拉菜单导航出现的问题吗? - CSS - Can someone help me figure out where I went wrong with my dropdown menu nav? 你能告诉我我哪里做错了吗? - Can you tell me where i did wrong? Javascript 表单验证不起作用,不知道我哪里出错了 - Javascript form validation not working, not sure where I went wrong 您可以为bootstrap v4中的弹出窗口提供有效的jsfiddle还是告诉我这是什么问题? - can you provide a working jsfiddle for popovers in bootstrap v4 or tell me what's wrong with this one? 我的Jquery按钮-禁用/启用功能不起作用。 谁能告诉我怎么了? - My Jquery button- disable/enable function is not working. Can anyone tell me what's wrong? 使用JS和SCSS的导航动画,你能告诉我我哪里出错了吗? - Navigation animation using JS and SCSS, can you tell me where I'm going wrong? 有人可以告诉我错误在哪里吗? 说$未定义,预期对象 - Can some tell me where is the error? saying $ not defined, object expected 石头,纸,剪刀的增量得分不起作用,有人可以告诉我我做错了吗? - Rock, Paper, Scissors Increment Score not working, can somebody tell me what i'm doing wrong? CSS-需要帮助找出下拉菜单导航出错的地方 - CSS - Need help figuring out where I went wrong with my dropdown menu nav
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM