个性化阅读
专注于IT技术分析

使用Bootstrap 4在桌面屏幕右侧的菜单

我是WordPress开发的新手, 我希望学习尽可能多。我正在从头开始构建主题, 并使用wp-bootstrap-navwalker(https://github.com/wp-bootstrap/wp-bootstrap-navwalker)作为我的显示的后备。

这是我目前拥有的:

使用Bootstrap 4在桌面屏幕右侧的菜单

如何将菜单选项移至屏幕右侧, 从而影响移动版本, 如下所示?

使用Bootstrap 4在桌面屏幕右侧的菜单

我想保持移动版本不变, 只是将桌面版本移到右侧-我尝试应用不同的属性以使其移到右侧, 但是移动版本不起作用。

这是代码:header.php

<nav class="navbar navbar-expand-md navbar-dark bg-primary">
<div class="container">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <?php
            wp_nav_menu( array(
                'theme_location'  => 'header-menu', 'depth'           => 2, // 1 = no dropdowns, 2 = with dropdowns.
                'container'       => 'div', 'container_class' => 'collapse navbar-collapse', 'container_id'    => 'bs-example-navbar-collapse-1', 'menu_class'      => 'navbar-nav mr-auto', 'fallback_cb'     => 'WP_Bootstrap_Navwalker::fallback', 'walker'          => new WP_Bootstrap_Navwalker(), ) );
        ?>
</div>

#1


使用以下内容进行锻炼:

.navbar-collapse > ul {
    margin-left: auto!important;
}

#2


你可以在保存菜单的<div>上使用Bootstrap类justify-content-end(带有navbar-collapse类的菜单)。检查下一个样本:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<nav class="navbar navbar-dark navbar-expand-md bg-primary">

  <a class="navbar-brand" href="#">Navbar</a>

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="navbar-collapse collapse justify-content-end">
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" href="#">Home</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Staff</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Specialty Area</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">Research Tools</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">More</a>
        </li>
    </ul>
  </div>

</nav>
赞(0)
未经允许不得转载:srcmini » 使用Bootstrap 4在桌面屏幕右侧的菜单

评论 抢沙发

评论前必须登录!