twitter-bootstrap Bootstrap 折叠菜单打开然后立即再次折叠
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36110757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap Collapsed menu opening then immediately collapsing again
提问by Shawn de Wet
I have a site using bootstrap. See running version here: www.ecomportal.co.za.
我有一个使用引导程序的网站。在此处查看运行版本:www.ecomportal.co.za。
When the window size reduces to mobile, the navbar menu correcly collapses to the usual 3-stripe button. My problem is that when I click this button to open the menu, it opens, but then immediately collapses again.
当窗口大小减小到移动时,导航栏菜单会正确折叠为通常的 3 条纹按钮。我的问题是,当我单击此按钮打开菜单时,它会打开,但随后又立即折叠起来。
I dont know where to start looking to resolve this problem.
我不知道从哪里开始寻找解决这个问题的方法。
Please help?
请帮忙?
回答by Shawn de Wet
Uhg, it turns out I had a major brain fart! I was using a bootstrap 2.x CSS file, along with a bootstrap 3.x js file.
呃,原来我脑子里放了个大屁屁!我使用了一个 bootstrap 2.x CSS 文件,以及一个 bootstrap 3.x js 文件。
回答by Mehravish Temkar
An inclass is added when a click is triggered to open the menu but the collapseclass isn't removed.
Adding this css for overriding collapseproperties worked for me:
一个in当点击触发打开菜单类添加,但collapse类不会被删除。添加这个用于覆盖collapse属性的css对我有用:
.navbar-collapse.in {
display: block !important;
}
回答by Danny
I came across this problem aswell, and fixed it by updating my bootstrap link.
我也遇到了这个问题,并通过更新我的引导程序链接来修复它。
回答by Kiran Maniya
You have Version Mismatch in bootstrap.css and bootstrap.js file/cdn. check once and you will realize the cause.
您在 bootstrap.css 和 bootstrap.js 文件/cdn 中有版本不匹配。检查一次,你就会明白原因。
回答by staxim
I had my .navbar-togglerbutton as a child element of .navbar-brand, and that caused an immediate open/close of the navigation links when clicking on the toggler button. Moving the button to be a sibling element fixed the issue. Silly mistake, and easy fix.
我将我的.navbar-toggler按钮作为 的子元素.navbar-brand,这会导致在单击切换按钮时立即打开/关闭导航链接。将按钮移动为同级元素解决了该问题。愚蠢的错误,易于修复。
回答by H.B
The issue resides in the opening mechanisms not the closing :
问题在于开放机制而不是关闭机制:
It only closes on the second click, but it never opens on the first click due to height = 0 of the navbar. Do you have a special JS or CSS running on your site ?
它只在第二次点击时关闭,但由于导航栏的高度 = 0,它永远不会在第一次点击时打开。您的网站上是否有特殊的 JS 或 CSS 正在运行?
If not, find two possible and likely solutions in this post. The first answer is the solution. Second one is a suggestion for your problem.
如果没有,请在这篇文章中找到两种可能的解决方案。第一个答案是解决方案。第二个是针对您的问题的建议。
Plus the data-target attribute starts with a . ,not sure if you intended that (just an observation)
另外 data-target 属性以 . ,不确定您是否打算这样做(只是观察)
Good luck
祝你好运

