Bootstrap Dropdown menu is not working

后端 未结 18 620
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 23:18

I am having trouble getting my dropdowns to work. I can get the navbar to show up perfectly, but when I click on \"Dropdown\" (either of them) it does not display the dropdo

相关标签:
18条回答
  • 2020-11-30 23:57

    If you face the problem in Ruby on Rails, the exhaustive solution is provided by Bootstrap Ruby Gem readme file.

    or in short:

    1. rename application.css to application.scss
    2. add @import "bootstrap";
    3. add gem 'jquery-rails' to Gemfile unless it exists.
    4. add //= require jquery3 //= require popper //= require bootstrap //= require bootstrap-sprockets to application.js.
    0 讨论(0)
  • 2020-11-30 23:59

    According to getBootstrap.com, dropdowns are built on third-party library Popper.js. So, if the dropdown menu does not work onclick but is working only on hover of the dropdown include popper.js, bootstrap.js and bootstrap.css. Not including popper.js before including bootstrap bundles could be one of the reasons.

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"></link>
    

    https://getbootstrap.com/docs/4.0/components/dropdowns/

    0 讨论(0)
  • 2020-12-01 00:02

    Maybe someone out there can benefit from this:

    Summary (a.k.a. tl;dr)

    Bootstrap dropdowns stopped dropping down due to upgrade from django-bootstrap3 version 6.2.2 to 11.0.0.

    Background

    We encountered a similar issue in a legacy django site which relies heavily on bootstrap through django-bootstrap3. The site had always worked fine, and continued to do so in production, but not on our local test system. There were no obvious related changes in the code, so a dependency issue was most likely.

    Symptoms

    When visiting the site on the local django test server, it looked perfectly O.K. at first glance: style/layout using bootstrap as expected, including the navbar. However, all dropdown menus failed to drop down.

    No errors in the browser console. All static js and css files were loaded successfully, and functionality from other packages relying on jquery was working as expected.

    Solution

    It turned out that the django-bootstrap3 package in our local python environment had been upgraded to the latest version, 11.0.0, whereas the site was built using 6.2.2.

    Rolling back to django-bootstrap3==6.2.2 solved the issue for us, although I have no idea what exactly caused it.

    0 讨论(0)
  • 2020-12-01 00:03

    Maybe try with

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
    

    and see if it will work.

    0 讨论(0)
  • 2020-12-01 00:06

    I am using rails 4.0 and ran into the same problem

    Here is my solution that passed test

    add to Gemfile

    gem 'bootstrap-sass'
    

    run

    bundle install
    

    then add to app/assets/javascripts/application.js

    //= require bootstrap
    

    Then the dropdown should work

    By the way, Chris's solution also work for me.

    But I think it is less conform to the asset pipeline idea

    0 讨论(0)
  • 2020-12-01 00:07

    Put the jquery js link before the bootstrap js link like so:

    <script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="Scripts/bootstrap.min.js"></script>
    

    instead of:

    <script type="text/javascript" src="Scripts/bootstrap.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
    
    0 讨论(0)
提交回复
热议问题