Button dropdown in Bootstrap not positioned below the button

I am struggling with the placement of a bootstrap button dropdown. Instead of appearing below the button, it is currently showing up underneath another div. Despite spending several hours on this issue, I have not been able to resolve it.

HTML

    <!DOCTYPE html>
    <html lang="en">

    <head>
      <link href="css/style.css" rel="stylesheet" />
      <script src="js/jquery.min.js"></script>
      <script src="js/bootstrap.min.js"></script>
    </head>

    <body class="nav-md">
      <div class="container body">
        <div class="main_container">
          <div class="col-md-3 left_col">
            <div class="left_col scroll-view"> </div>
          </div>
          <!-- page content -->
          <div class="right_col" role="main">
            <div class="">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_content">
                    <div class="" data-example-id="togglable-tabs" role="tabpanel">
                      <ul class="nav nav-tabs bar_tabs" id="myTab" role="tablist">
                        <li class="active" role="presentation"> <a aria-expanded="true" data-toggle="tab" href="#tab_content1" id="home-tab" role="tab"><i class="fa fa-globe"></i> Tab 1</a></li>
                      </ul>
                      <div class="tab-content" id="myTabContent">
                        <div aria-labelledby="home-tab" class="tab-pane fade active in" id="tab_content1" role="tabpanel">
                          <div class="row">
                            <div id="saveloaddiv" style="float:right;display:inline-block;"> <button data-toggle="dropdown" class="btn btn-success dropdown-toggle btn-xs" type="button" aria-expanded="true">Success <span class="caret"></span>
                                        </button>
                              <ul role="menu" class="dropdown-menu">
                                <li><a href="#">Action</a> </li>
                                <li><a href="#">Another action</a> </li>
                                <li><a href="#">Something else here</a> </li>
                                <li class="divider"></li>
                                <li><a href="#">Separated link</a> </li>
                              </ul>
                            </div>
                          </div>
                          <div class="clearfix"></div>
                          <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                              <div id="text">
                                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- /page content -->
        </div>
      </div>
    </body>
    </html>

The implementation utilizes the twitter bootstrap content delivery network for its CSS and JavaScript files.

A demonstration of the issue can be viewed through this fiddle: https://jsfiddle.net/rdawkins/f7m6cv7q/8/

Answer №1

To find the solution, you need to utilize the CSS property position: relative;.

Enclose both the button and dropdown menu within a parent div, setting the container's positioning to position: relative;. Use CSS to position the menu below the button.

Check out this updated JSFiddle as well as the additional code provided below.

HTML

<div class="dropdown-container"><!--Container wrapped around-->
  <button data-toggle="dropdown" class="btn btn-success dropdown-toggle btn-xs" type="button" aria-expanded="true>Success <span class="caret"></span>
  </button>
  <ul role="menu" class="dropdown-menu">
    <li><a href="#">Action</a> </li>
    <li><a href="#">Another action</a> </li>
    <li><a href="#">Something else here</a> </li>
    <li class="divider"></li>
    <li><a href="#">Separated link</a> </li>
  </ul>
</div><!--End of Container-->

CSS

.dropdown-container {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%; /* Positioned below the button */
  right: 0;
  margin-left: -100px; /* Adjusted further left */
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Laravel issues with displaying data in a 'foreach' loop

I encountered a quirky issue while working with Laravel 5.2. I have a chunk of text that I'm attempting to display using some explode functions. The strange part is, Laravel is rendering it oddly by adding incorrect ':' before the end of the ...

Differences in behavior of Backbone.js Ajax calls between Chrome and Firefox

I am encountering an unusual problem in Firefox. When we load a page and call Routers.initializeRouters(); an ajax request is sent to fetch the data, and the loadFormSuccessHandler function populates the response into the views. In Chrome, the Ajax reques ...

What steps do I need to take in order to create a web-based file uploader that supports simultaneous uploads of multiple files

Is there a way to create the ability for users to upload multiple files at once on a Django/Python/jquery website, similar to the Gmail file selection feature? I am looking to allow users to select multiple files from their browser file selector and uplo ...

The jQuery regular expression for validating US postal codes is not functioning correctly

After implementing the code snippet provided, I noticed that no alert message is being displayed when non-numeric values are entered into the Zipcode field. Can someone please help me troubleshoot this issue? $("input:text[name='address_1[zip]&apos ...

Top navigation bar paired with collapsible side panel

Has anyone come across a basic Bootstrap dashboard template that doesn't display the toggler icon on mobile devices? I'm looking for a solution to keep the sidebar visible on large screens but hide it under a toggler button (hamburger menu) on mo ...

Setting variables in AngularJS services without encountering JavaScript undefined errors

After developing an AngularJS module, I attempted to link a service and use it to share variables across the application. While most things are functioning properly, I encountered an issue when trying to set submenu[1] to an object. The error message sta ...

Is it true that outerHeight(true) excludes margins?

As stated in the JQuery documentation, the outerHeight(true) function should return the complete height of an element, including padding, border, and margins. However, I encountered a scenario where this functionality seemed to be flawed. You can find a co ...

Create a dynamic menu dropdown with absolute positioning using React

I recently made the transition to React and now I am in the process of converting my old vanillaJS website into ReactJS. One issue I am facing is with a button that is supposed to trigger the opening of a dropdown menu. <button type="button&qu ...

CSS: What's with the weird gray element appearing in Safari?

Does anyone have a solution for removing the grey layer (cf the image) in Safari? This issue does not occur in Chrome. The structure is as follows: <div class="class1"> <div class="class2"> <select> ... </selec ...

Minimizing load time to create a seamless user experience

After working diligently on a website, we successfully reduced the total content for a page load from 13.7MiB's to 2.4, but unfortunately, the page still loads at a snail's pace. This Joomla site is loaded with redundant DOM elements (2000+ for ...

What is causing this unexpected text to display in Django when encountering errors while trying to submit a form?

On my website, there is a form that collects an employee number and validates it against another model called Salesman. It also checks if the employee's team field includes 'WF'. The validation process functions correctly and displays everyt ...

Experience the smooth glide on a CSS image

I am looking to add a unique animation to my menu, specifically a slide-down color effect instead of the typical fade transition on the first two divs. I envision it as a curtain-like animation. When hovering over an image, I want a colored panel to smoot ...

A guide to incorporating external CSS files in Angular 5 components using styleUrls

I have a unique setup where my Angular 5 application resides in a subdirectory within another parent application. The parent application consists of JSP and other AngularJS applications among other things. My goal is to include a CSS file from the parent ...

Selenium's ByChained, By.CssSelector, By.XPath, and ByJQuery.ByJQuerySelector are not meeting my expectations in terms of functionality

I'm struggling with identifying a specific selector. My NUnit test keeps failing when it reaches the selector. I need some assistance to correct this issue. Let's dive into an example. Here is the HTML code: <div class="form-item required ro ...

Styling unique text in an HTML text area

In the process of creating a web-based SQL editor, I am looking for a way to apply unique styling to certain SQL keywords (such as select, create, from) while a user is typing. Is there a way to achieve this using HTML alone? Alternatively, are there any ...

Perfectly aligning the Update Progress Animation in real-time

I am currently utilizing the Ajax UpdateProgress with a loading gif attached. The issue I am facing is how to ensure that the loading.gif always appears in the center of the screen, even if the user is at the very top or bottom of the page. Is there a meth ...

The dropdown feature in Safari fails to collapse when an option is selected

I've encountered an issue with my code using Bootstrap 4 and it's functioning correctly on IE 11 and Firefox, but not on Safari for Mac. The content remains hidden when selecting an option from the dropdown menu in Safari. My intention is to hid ...

Tips for reaching a node.js application deployed on Heroku

Trying to deploy my node.js app to Heroku has been a challenge. Despite watching various tutorials and reading the documentation, I'm stuck on how to send and receive data from the hosted node.js app. The communication between my webpage and the node. ...

What is the best way to iterate through only the selected checkboxes to calculate their

I am in need of calculating the selected checkboxes only within a table field (harga_obat*jumlah) Below is my foreach data: @foreach ($obat as $o) <tr> <td> <input id="check" type="checkbox" name="select[]" value="{{ $o->nam ...

Fluid container and confined container

Can someone explain the guidelines for when to use container versus container fluid in web development? What are some best practices and common pitfalls to avoid when using these two options? I would appreciate a clear explanation of the differences betwe ...