Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

position dropdown button and dropdown menu in center?

<div class="dropup center-block">
            <button class="btn btn-info dropdown-toggle center-block" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">About Me<span class="caret"></span></button>
          <ul class="dropdown-menu">
            <li class="dropdown-header">Dropup stuff</li>
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </div>

added center-block to both div and button, but unable to get the dropup menu positioned center.

A similar thing can be found at "Dropdown Position" in this page. The button is aligned left, but the menu is right. I'm able to align the menu right but not center.

Please help!

like image 575
azam Avatar asked Jul 17 '16 09:07

azam


People also ask

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

Use data-offset or data-reference to change the location of the dropdown.

How do you put a drop down arrow under a caret in bootstrap 4?

To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. The . caret class creates a caret arrow icon (), which indicates that the button is a dropdown.

How can I create multiple dropdowns in bootstrap?

No, it's not possible to have two dropdown menus inside the same div . They need to be separated since the code to toggle them looks for the first element in the parent div of the button/anchor. So if they are in the same parent div only the first will be toggled.

What are the drop down menus called?

A drop-down menu is also known as a pull-down menu, pull-down list, drop-down list or drop-down box.


2 Answers

A little trick add some css rules,text-center with dropdown class and dropdown-menu-center to the list.

source: https://stackoverflow.com/a/28078054/6142097

.dropdown-menu-center {
  left: 50% !important;
  right: auto !important;
  text-align: center !important;
  transform: translate(-50%, 0) !important;
}
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<div class="container">
  <h2>Dropdowns</h2>
  <div class="dropdown text-center">
    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
    <span class="caret"></span></button>
    <ul class="dropdown-menu dropdown-menu-center">
      <li><a href="#">HTML</a></li>
      <li><a href="#">CSS</a></li>
      <li><a href="#">JavaScript</a></li>
      <li class="divider"></li>
      <li><a href="#">About Us</a></li>
    </ul>
  </div>
</div>
like image 156
mihkov Avatar answered Oct 21 '22 06:10

mihkov


Try adding a margin-left

 <div class="dropup center-block" style="margin-left: 49%;"> 
like image 41
dresdain Avatar answered Oct 21 '22 06:10

dresdain