我在CSS中将这个垂直导航栏变成水平导航栏时遇到了麻烦

时间:2018-02-27 04:35:10

标签: html css twitter-bootstrap bootstrap-4

<nav class="navbar navbar-dark bg-dark sticky-top">
  <a class="navbar-brand" href="#">I/H</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="index.html">Home<span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#about">About</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#work">Work</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#connect">Connect!</a>
      </li>
    </ul>
  </div>
</nav>

我想删除按钮并使用CSS将这个坏男孩变成水平导航栏,但我遇到了麻烦。有什么建议?在看了几百种不同的方法之后,我无法弄明白。如果我将按钮留在那里,每次我点击它并打开下拉菜单时,直接位于下方的社交媒体图标会移动到不同的位置。因此,我决定删除按钮并将此垂直列表设置为水平列表,而不是试图弄乱它,但当我尝试它时,它不起作用。

它已经解决了!

1 个答案:

答案 0 :(得分:0)

您只需要使用Bootstrap的navbar-expand类......

https://www.codeply.com/go/fDfvWpQh71

<nav class="navbar navbar-expand navbar-dark bg-dark sticky-top">
    <a class="navbar-brand" href="#">I/H</a>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link" href="index.html">Home<span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#about">About</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#work">Work</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#connect">Connect!</a>
            </li>
        </ul>
    </div>
</nav>