Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 dropdown menu center align not working

Tags:

I am not able to align the dropdown to the center of the parent on which the dropdown is opened with hover. I have tried to text-align: center for the entire .nav .navbar li elements, and it doesn't work. I have tried to set margin and left: 50% for the entire ul.dropdown-menu that is the dropdown and it doesn't work. Here is the html code:

<ul class="nav navbar-nav navbar-right" id="headerDropdowns">   <li><div class="btn-toolbar">     <div class="btn-group">       <button class="btnCustom" data-toggle="dropdown" data-hover="dropdown" data-delay="1000">Our Difference</button>       <ul class="dropdown-menu">         <li><a tabindex="-1" href="#">Made in the USA</a></li>         <li class="divider"></li>         <li><a tabindex="-1" href="#">Human Grade</a></li>         <li class="divider"></li>         <li><a tabindex="-1" href="#">Ingredients Fresh</a></li>         <li class="divider"></li>         <li><a tabindex="-1" href="#">USDA Meats</a></li>         <li class="divider"></li>         <li><a tabindex="-1" href="#">Our Story</a></li>         <li class="divider"></li>         <li><a tabindex="-1" href="#">Campare</a></li>       </ul>     </div>   </li> </ul> 

In which class dropdown-menu, or nav navbar-nav, should I do the aligment, and what should I set?

like image 821
Matija Avatar asked Sep 01 '14 17:09

Matija


People also ask

How do I center a drop down menu 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.

How do I change the position of a drop down menu in HTML?

HTML) Use any element to open the dropdown content, e.g. a <span>, or a <button> element. Use a container element (like <div>) to create the dropdown content and add whatever you want inside of it. Wrap a <div> element around the elements to position the dropdown content correctly with CSS.

How do I adjust a form in center?

Use the CSS text-align Property to Center a Form in HTML We can set the value to center to center the form. For example, apply the text-align property to the form tag in the style attribute, and set the property to center . Next, create input tags with the type text and then submit .


1 Answers

You can use transform to avoid having to use fixed widths:

.dropdown-menu {   left: 50%;   right: auto;   text-align: center;   transform: translate(-50%, 0); } 

Answer influenced by http://css-tricks.com/centering-percentage-widthheight-elements/

like image 199
phpMagpie Avatar answered Oct 25 '22 04:10

phpMagpie