向Bootstrap导航栏添加字幕

时间:2018-09-15 20:26:29

标签: html css bootstrap-4 navbar nav

我有一个带有导航栏的Bootstrap 4网站。导航栏有一个brand部分,其中包含图像和标题文本,然后是导航栏的其余部分。您可以在这里看到它:https://jsfiddle.net/zmbq/aq9Laaew/218793/

现在,我想在“ A Digital Onomasticon”标题下添加一个字幕。问题是-字幕很长,我希望它可以扩展到导航链接下方。

我尽我所能想到的一切,却不知道该怎么做。

注意:对this question的回答还不够,因为它会产生如下内容:https://jsfiddle.net/zmbq/7et2uz0w/

2 个答案:

答案 0 :(得分:2)

您可以将字幕设置为绝对位置,以将其从常规内容流中删除。目前尚不清楚它在手机上的外观,我只是将其隐藏在媒体查询中。示例:

<a class="navbar-brand" href="#">
  <img src="http://onomasticon.researchsoftwarehosting.org/assets/images/seal-impression.png">
  A Digital Onomasticon
  <small>A lot more text that goes under the links and should be cleverly placed, and isn't</small>
</a>

.navbar-brand small {
  display: block;
  font-size: 10px;
  white-space: normal;
  position: absolute;
}

@media (max-width: 575.98px) {
  .navbar-brand small {
    display: none;
  }
}

JsFiddle

答案 1 :(得分:1)

将品牌和链接包装在单独的flexbox(d-flex)分区中...

<nav class="navbar navbar-light bg-light navbar-expand-sm flex-nowrap align-items-start">
    <a class="navbar-brand" href="#">
        <img src="http://onomasticon.researchsoftwarehosting.org/assets/images/seal-impression.png">
    </a>
    <div class="d-flex flex-column">
        <div class="d-sm-flex d-block flex-nowrap">
            <a class="navbar-brand" href="#">A Digital Onomasticon</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarOnavbarNavptions" 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">
                        <a class="nav-link" href="#">Item one</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Item two</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Item three</a>
                    </li>
                </ul>
            </div>
        </div>
        <small>A lot more text that goes under the links and should be cleverly placed, and isn't</small>
    </div>
</nav>

https://www.codeply.com/go/9SK8ItOyzw


相关:Bootstrap 4 navbar with 2 rows