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
If you face the problem in Ruby on Rails, the exhaustive solution is provided by Bootstrap Ruby Gem readme file.
or in short:
application.css
to application.scss
@import "bootstrap";
gem 'jquery-rails'
to Gemfile
unless it exists.//= require jquery3
//= require popper
//= require bootstrap
//= require bootstrap-sprockets
to application.js
.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/
Maybe someone out there can benefit from this:
Bootstrap dropdowns stopped dropping down due to upgrade from django-bootstrap3
version 6.2.2
to 11.0.0
.
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.
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.
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.
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.
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
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>