Bootstrap 4 –导航栏折叠时如何连续显示项目?

时间:2018-11-30 23:49:39

标签: html css bootstrap-4

当窗口在导航栏中折叠时,我想彼此相邻显示一些项目。当前,它在诸如Navbar collapsed的列中显示项目。我要在用户名旁边添加图片。

 <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</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="ml-auto navbar-nav border border-primary rounded" style="background:blue">

        <li class=" nav-item active">
          <a class="nav-link" href="#">Hi, Shadow <span class="sr-only">(current)</span></a>
        </li>
        <li id="something1" class="mt-auto mb-auto nav-item">
          <img id="something" src="images/space_stars_blue_free_wallpaper.jpg" class="img-fluid rounded-circle "
            alt="..." width="50" height="50">
        </li>
      </ul>
</div>

3 个答案:

答案 0 :(得分:0)

使用Bootstrap 4时,它们具有用于无序列表及其列表项的内联列表类。看起来像这样:

import requests, bs4
res = requests.get('https://www.oddsshark.com/ncaab/odds')
odds = bs4.BeautifulSoup(res.text, 'html.parser')

# This, another identifier from the same site, works fine.
print(str(len(odds.select('.op-opening'))))

# However, this does not.
print(str(len(odds.select('.op-bovada.\lv'))))
print(str(len(odds.select('.op-bovada.\\lv'))))

这里是查看Bootstraps官方文档的链接: http://v4-alpha.getbootstrap.com/content/typography/#inline

答案 1 :(得分:0)

navbar-nav navbar列表项设置为display: inline-block即可:

.navbar-nav {
    display: inline-block;
}

.navbar-nav > li {
    display: inline-block;
}

答案 2 :(得分:0)

只需将flex-row类添加到navbar-nav ...

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <a class="navbar-brand" href="#">Navbar</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="ml-auto navbar-nav border border-primary rounded flex-row" style="background:blue">
            <li class=" nav-item active">
                <a class="nav-link" href="#">Hi, Shadow <span class="sr-only">(current)</span></a>
            </li>
            <li id="something1" class="mt-auto mb-auto nav-item">
                <img id="something" src="//placehold.it/50" class="img-fluid rounded-circle ml-1" alt="..." width="50" height="50">
            </li>
        </ul>
    </div>
</nav>

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