Harsha Rama
Harsha Rama

Reputation: 349

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

Upvotes: 0

Views: 430

Answers (2)

MaDD
MaDD

Reputation: 58

I went throught your code. I noticed 2 issues.

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

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

Here is a fiddle demo.

JS Fiddle Demo

Here is the structure of the 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>

Upvotes: 1

Getz
Getz

Reputation: 4053

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

Upvotes: 0

Related Questions