Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap dropdown bubble align right (not push-right)

I have cart in my top menu, using push-right and my problem is that the dropdown bubble falls out of the page. I am trying to align the bubble right, so that it right-aligns with 'click'

like this

enter image description here

HTML:

<div class="cart pull-right">
  <ul class="nav">
    <li class="dropdown">
      <a class="dropdown-toggle" data-toggle="dropdown" href="#">CLICK</a>
       <div class="dropdown-menu">
       STUFF
       </div>
    </li>
  </ul>
</div>
like image 314
no0ne Avatar asked Sep 19 '13 10:09

no0ne


People also ask

How do I align a drop down to the right?

Use the w3-right class to float the dropdown to the right, and use CSS to position the dropdown content (right:0 will make the dropdown menu go from right to left).

How do I move a dropdown to the right in Bootstrap?

To right-align a menu, use . dropdown-menu-right.

How do I position a drop down menu in Bootstrap?

By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add . dropdown-menu-right to a . dropdown-menu to right align the dropdown menu.

How do I move a drop down center in Bootstrap?

Dropdown button can be positioned in the center of the page by setting the “text-align” property of dropdown div to center. The following example contains a simple Bootstrap dropdown menu with an added class “my-menu”. The property “text-align: center” is added to the class.


3 Answers

Bootstrap 5+ (Update June 2022)

dropdown-menu-right has been replaced with dropdown-menu-end

<div class="dropdown-menu dropdown-menu-end">
    STUFF
</div>

https://getbootstrap.com/docs/5.2/components/dropdowns/#menu-alignment

Bootstrap 3.1+

Adding the class .dropdown-menu-right to the same div containing the class dropdown-menu:

<div class="dropdown-menu dropdown-menu-right">
    STUFF
</div>

http://getbootstrap.com/components/#dropdowns-alignment

Bootstrap 2.3 & 3.0

Add the class .pull-right to the same div containing the class dropdown-menu

<div class="dropdown-menu pull-right">
    STUFF
</div>

This seems to work for me using bootstrap 3.0

like image 151
meetri Avatar answered Oct 14 '22 23:10

meetri


This can be solved with the bootstrap class dropdown-menu-right with dropdown-menu that is specifically for this problem that uses the css properties right: 0; and left: auto; to right align it.

This solution is working for me.

Source - http://getbootstrap.com/components/#btn-dropdowns-dropup (go to developer tools for this)

like image 35
Jaspreet Singh Avatar answered Oct 14 '22 23:10

Jaspreet Singh


<div class="dropdown-menu dropdown-menu-right">

This is still working in boostrap 4.2.1 :)

like image 24
Georgi Peev Avatar answered Oct 15 '22 00:10

Georgi Peev