twitter bootstrap input append dropdown button appears on wrong side of input when in a table

Go To StackoverFlow.com

5

The html below works fine by itself but when put inside a table td, the drop down button appears on the left side of the input when it should be on the right side. It should look something like the append with button example in the 'Extending form controls' section of this page: http://twitter.github.com/bootstrap/base-css.html#forms

Both items have the correct shape. ie. the rounded corners and the straight edges are on the correct sides but because the button is on the left side of the input, the straight edges don't line up. Its the rounded corners that are next to one another. I want them to appear as in the markup, with the input side by side with the drop down button, appearing to be joined together. Even if a try using the class "input-prepend' (not that a want it that way) it doesn't change.

Note: I'm using twitter bootstrap in a rails application via the latest version of the twitter-bootstrap-rails gem.

<div class="btn-group input-append">    
    <input class="span2" id="fruit_selection" name="fruit" />           
    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Fruit <span class="caret"></span></a> 
    <ul class="dropdown-menu">
        <li><a href="#">apple</a></li>
        <li><a href="#">orange</a></li>
        <li><a href="#">banana</a></li>
    </ul>   
</div>  
  • The only css I have is what came with twitter bootstrap and also jquery ui.
  • Its the same in safari and firefox.
  • Its within form tags.
  • I've tried as many combinations of divs, spans, classes(append, prepend, btw-group, add-on, control-group etc) that I can think of.

Am I doing it wrong ? Is there any extra css I can add to make it work? Any help would be appreciated.

For bonus points: The append and prepend example( http://twitter.github.com/bootstrap/base-css.html#forms ) doesn't work on my site either in or out of a table. I can only use one or the other not both at the same time.

2012-04-03 22:59
by Daniel
Can you post a test case on http://jsfiddle.net - Andres Ilich 2012-04-03 23:23
Never heard of jsfiddle before. seems pretty clever. Not totally sure I've don't it right be heres my attempt: http://jsfiddle.net/N6vGZ/1/ Note: its a bit different to my result in that the button here is falling onto a new line. Maybe has the same fix though - Daniel 2012-04-04 00:42
so you want the dropdown to be position to the left or right of the input field - Andres Ilich 2012-04-04 00:53
dropdown on the right side - Daniel 2012-04-04 01:37


4

I see what you're trying to do now, you want to use an input instead of a button with the dropdown group. Looking over the documentation of the bootstrap i found no solution for that setup though you can easily emulate your own by copying the button behavior and just creating your own class to support an input with a dropdown group, like so:

CSS

.btn-group .input:first-child {
    border-bottom-left-radius: 4px;
    border-top-left-radius: 4px;
    margin-left: 0;
}

.btn-group .input {
    float: left;
    position: relative;
}

With this CSS in place all you have to do is include the .input class in your input field and it should work:

HTML

<div class="btn-group">    
    <input class="span2 input" id="fruit_select" name="fruit" />            
    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Fruit <span class="caret"></span></a>
    <ul class="dropdown-menu">
        <li><a href="#">apple</a></li>
        <li><a href="#">orange</a></li>
        <li><a href="#">banana</a></li>
    </ul>
</div>

Demo, edit here.

2012-04-04 01:11
by Andres Ilich
Thank you. That looks like its going to be the best way to get it working. Even though the documentation doesn't show it, when I put it outside of the table it works. See the second one added here http://jsfiddle.net/N6vGZ/3/ Although the input size looks wrong on fiddle its ok on mine - Daniel 2012-04-04 01:33
After further testing of the css you provided, the only part a need to use is .btn-group .input { float: left; } The twitter-bootstrap css must do the res - Daniel 2012-04-04 04:48
@Daniel make sure the margin looks ok as well, you might have a 1px margin difference - Andres Ilich 2012-04-04 10:59


0

Try to wrap your lists inside a div with class as control-group - an example is given below. I know you mentioned that you tried control-group but give it another shot. this code worked for me after a lot of trial and error.. good luck.

<div class="control-group">
  <div class="controls">  
    <ul class="dropdown-menu">
        <li><a href="#">apple</a></li>
        <li><a href="#">orange</a></li>
        <li><a href="#">banana</a></li>
    </ul>   
  </div>
</div>
2012-04-04 00:56
by Prashanth
Thanks for your help. For some reason its not working for me. Will do some more trial and error myself - Daniel 2012-04-04 01:36
Ads