简体   繁体   English

Bootstrap 4 Navbar切换中断

[英]Bootstrap 4 Navbar Toggle Broken


I am currently doing some responsive work on a new Wordpress site I am building. 我目前正在我正在建立的新的Wordpress网站上进行响应式工作。 It is a custom theme built on Underscores and so I have included the bootstrap files for use on the navbar and grid columns. 这是一个基于Underscores的自定义主题,因此我包含了用于navbar和grid列的引导文件。 All the bootstrap functions are working correctly, only when my navbar drops down into tablet view (with the menu items hidden and the toggle button showing), when the page is loaded, the navbar loads opened and then when the toggle button is clicked, it slides up and immediately reopens again. 仅当我的导航栏进入平板电脑视图时(隐藏菜单项并显示切换按钮),加载页面时,导航栏加载打开,然后单击切换按钮时,所有引导程序功能才能正常工作向上滑动并立即重新打开。

The classes applied to the navbar when the page loads are: 页面加载时应用于导航栏的类为:

<div class="navbar-collapse collapse">

And then once the navbar toggle is clicked: 然后单击导航栏切换:

<div class="navbar-collapse collapse in">

I have no console errors so i'm a little stuck. 我没有控制台错误,所以有点卡住了。 Here is a GIF to show whats happening: 这是GIF,用于显示发生的情况: 在此处输入图片说明

Any help would be greatly appreciated! 任何帮助将不胜感激!

Full NavBar Code, please note that the navigation links are being loaded by the wp_nav_menu() function in WordPress. 完整的NavBar代码,请注意,导航链接是由WordPress中的wp_nav_menu()函数加载的。

<nav id="site-navigation" class="main-navigation navbar navbar-expand-lg">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation-bar" aria-controls="navigation-bar" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="nav-right">
        <a href="tel:0"><img src="/assets/uploads/Navbar-Icon-Phone.png" alt="Call Omicron Solutions"></a>
        <a href="mailto:lewis@email.com"><img src="/assets/uploads/Navbar-Icon-Email.png" alt="Email Omicron Solutions"></a>
    </div>
    <div class="collapse navbar-collapse" id="navigation-bar">
        <div class="menu-main-menu-container">
            <ul id="menu-main-menu" class="menu navbar-nav mr-auto mt-2 mt-lg-0">
                <li id="menu-item-128" class="nav-item menu-item menu-item-type-custom menu-item-object-custom menu-item-128">
                    <a href="index.php"><img src="/assets/uploads/Navbar-Icon-Home.png" alt="Home"></a>
                </li>
                <li id="menu-item-29" class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-29">
                    <a href="http://localhost/about/">About</a>
                </li>
                <li id="menu-item-28" class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-28">
                    <a href="http://localhost/services/">Services</a>
                </li>
                <li id="menu-item-27" class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-27">
                    <a href="http://localhost/case-studies/">Case Studies</a>
                </li>
                <li id="menu-item-26" class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-26">
                    <a href="http://localhost/news/">News</a>
                </li>
                <li id="menu-item-25" class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-25">
                    <a href="http://localhost/contact-us/">Contact Us</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Solved! 解决了! The problem was that I had a Page Builder plugin installed that called in Bootstrap 3. I completely missed this in the source and so I had Bootstrap 3 & 4 fighting over control for the navbar. 问题是我安装了在Bootstrap 3中调用的Page Builder插件。我在源代码中完全错过了这个插件,因此我让Bootstrap 3和4争夺了导航栏的控制权。

Note to self: Always check for duplicate bootstrap includes if using plugins. 自我注意:如果使用插件,请始终检查是否包含重复的引导程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM