Bootstrap 引导导航栏切换按钮,单击时左移

noj0wjuj  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(2)|浏览(284)

当我点击小屏幕上的bootstrap navbar-toggle按钮时,它会在navbar-collapse打开时向左移动一点,并在关闭时返回中心。

<nav class="navbar navbar-expand-sm navbar-light bg-default" data-toggle="affix">
    <div class="mx-auto d-sm-flex d-block flex-sm-nowrap">
        <button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#toggle-items" aria-expanded="false"
            aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse text-center" id="toggle-items">
            <ul class="navbar-nav">
                <li class="nav-item active">
                    <a class="nav-link" href="#">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">O Projeto</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Sobre Mim</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Blog</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Contato</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

CSS

.nav-link {
  font-family: "Cabo Slab-Regular";
  font-size: large;
  letter-spacing: 2px;
  color: white !important;
  padding: 10px;
  padding-left: 30px !important;
  padding-right: 30px !important;
}

.nav-link:hover {
  color: #e1e1e1 !important;
}

/* Extra small devices (portrait phones, less than 576px) */
@media (max-width: 575.98px) { 
  .nav-link {
    font-size: inherit;
    padding: 0;
    padding-left: 0 !important;
    padding-right: 0 !important;
  } 
}
7cwmlq89

7cwmlq891#

.mx-auto.d-sm-flex.d-block.flex-sm-nowrap {
    text-align: center;
}

这样当菜单打开时,.navbar-toggle按钮应该会在其父按钮中居中对齐,防止切换时出现不希望的左右跳跃效果。我仍然感觉不到它的跳跃,但这是一个很小的移动,可以通过一些额外的尝试和错误风格的调整来纠正。

h5qlskok

h5qlskok2#

.navbar-toggler { margin: 0 auto; }

相关问题