【问题标题】:fixed-top class of bootstrap menu is not working on large devices in WordPress引导菜单的固定顶级类在 WordPress 的大型设备上不起作用
【发布时间】:2020-02-24 19:01:24
【问题描述】:

我正在使用引导类 'navbar-fixed-top' 类来让导航栏贴在窗口的顶部,例如在这个例子中:

https://getbootstrap.com/examples/navbar-fixed-top/

以下是菜单代码。

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Awesome Theme</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <?php 
                wp_nav_menu(array(
                    'theme_location' => 'primary',
                    'container' => false,
                    'menu_class' => 'nav navbar-nav navbar-right',
                    'walker' => new Walker_Nav_Primary()
                    )
                );
                ?>
        </div>
    </div>
    <!-- /.container-fluid -->
</nav>

以下是大型设备上的菜单截图(无法正常显示)

菜单适用于中型设备,如下图所示

【问题讨论】:

    标签: wordpress twitter-bootstrap menu css-position


    【解决方案1】:

    您可以对屏幕尺寸使用 css 代码,例如:

    @media (min-width: 979px) {
    
        .navbar { ... }
    
    }
    

    结合 CSS 的 max-width 属性来实现你所需要的。 https://www.w3schools.com/cssref/pr_dim_max-width.asp

    【讨论】:

    • 我应该设置最大宽度吗?
    • 你可以说如果设备的最小宽度是 979 像素,那么例如将我的导航栏类的最大宽度设置为 900 像素。
    • 您使用的是真实的类名、真实的语法还是逻辑宽度检查?
    • 我正在使用此代码 @media (min-width: 968px) { .navbar{ max-width: 100%; } } 但仍然无法正常工作
    • 因为 "max-width: 100%" 使您的导航栏的宽度为屏幕的 100%。您应该将其指定为 px,例如“max-width: 960px”。
    猜你喜欢
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多