I have the following dropdown
<label class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">
Action <b class="caret"></b></label>
<ul class="dropdown-menu" role="menu" aria-labelledby="lang-selector" id="lang-selector">
dropdown content goes here
</ul>
The upper-left corner of the dropdown is at the lower-left corner of the text (Action), but I hope that the position of the upper-right corner of the dropdwon is at the lower-right place of the text. How can I do that?
This is the effect that we're trying to achieve:
The classes that need to be applied changed with the release of Bootstrap 3.1.0 and again with the release of Bootstrap 4. If one of the below solutions doesn't seem to be working double check the version number of Bootstrap that you're importing and try a different one.
Bootstrap 3
Before v3.1.0
You can use the
pull-right
class to line the right hand side of the menu up with the caret:Fiddle: http://jsfiddle.net/joeczucha/ewzafdju/
After v3.1.0
You can use the
dropdown-right
class to line the right hand side of the menu up with the caret:Fiddle: http://jsfiddle.net/joeczucha/1nrLafxc/
Bootstrap 4
The class for Bootstrap 4 are the same as Bootstrap > 3.1.0, just watch out as the rest of the surrounding markup has changed a little:
Fiddle: https://jsfiddle.net/joeczucha/f8h2tLoc/
If you wants to center the dropdown, this is the solution.
Even if it s late i hope i can help someone. if dropdown menu or submenu is on the right side of screen it's open on the left side, if menu or submenu is on the left it's open on the right side.
To detect vertical position you can also add
https://jsfiddle.net/jd1100/rf9zvdhg/28/
Not sure about how other people solve this problem or whether Bootstrap has any configuration for this.
I found this thread that provides a solution:
https://github.com/twbs/bootstrap/issues/1411
One of the post suggests the use of
I tested and it works.
Hope to know whether Bootstrap provides config for doing this, not via the above css.
Cheers.
If you want to display the menu up, just add the class "dropup"
and remove the class "dropdown" if exists from the same div.
Based on Bootstrap doc:
As of v3.1.0, .pull-right is deprecated on dropdown menus. use .dropdown-menu-right
eg: