创建具有两行的自适应Bootstrap导航栏 [英] Create responsive Bootstrap navbar with two rows

查看:158
本文介绍了创建具有两行的自适应Bootstrap导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个具有两行的基于响应式Bootstrap 3的导航栏.但是,我在处理HTML的结构和折叠功能方面遇到了麻烦.

I am trying to create a responsive Bootstrap 3 based navbar with two rows. However, I am having trouble with the structure of the HTML and the collapse functionality.

下面是对所需结果的直观描述,我希望有人可以在HTML/CSS方面为我指明正确的方向(具有尽可能多的默认Bootstrap功能).

Below is a visual description of the desired result, and I was hoping someone could point me in the right direction in terms of HTML/CSS (with as much default Bootstrap functionality as possible).

基本上,菜单需要执行以下操作:

  • 在平板电脑/台式设备上,第一行是徽标和菜单 小型辅助链接(Link1-3).第二行是主菜单 主要链接(LinkA-E).

  • On tablet/desktop devices, the first row is the logo and a menu of small secondary links (Link1-3). The second row is the main menu with main links (LinkA-E).

在移动设备上,经典折叠设计应 与徽标和汉堡包图标一起出现.展开的菜单应 首先显示主要链接(LinkA-E),然后显示次要链接 (Link1-3)最后.

On mobile, the classic collapse design should appear with the logo and hamburger icon. The expanded menu should show the main links (LinkA-E) first, and then the secondary links (Link1-3) last.

平板电脑/台式机设备:

|----------------------------------------------------------|
|  LOGO/BRAND                         Link1  Link2  Link3  |
|----------------------------------------------------------|
|  LinkA  LinkB  LinkC  LindD  LinkE                       |
|----------------------------------------------------------|

移动设备(折叠):

|--------------------------------------|
|  LOGO/BRAND               HAMBURGER  |
|--------------------------------------|

移动设备(展开):

|--------------------------------------|
|  LOGO/BRAND               HAMBURGER  |
|--------------------------------------|
|  LinkA                               |
|  LinkB                               |
|  LinkC                               |
|  LinkD                               |
|  LinkE                               |
|--------------------------------------|
|  Link1                               |
|  Link2                               |
|  Link3                               |
|--------------------------------------|

推荐答案

如果我有项目的html/css,我会用它来显示您应该如何做,但是在这种情况下此HTML >来自 Bootstrap v3.3.7的静态导航栏示例

If i had an html/css of your project i use it to show how you should do that, but in this context THIS HTML came from static navbar example of Bootstrap v3.3.7

从精妙的角度出发,将<div id="navbar" class="navbar-collapse collapse">放置在<div class="navbar-header">下面的行中,使其浮动并使其宽度占其空间的100%,然后使用margin-top: -50px;上拉<ul class="nav navbar-nav navbar-right">

actualy the idea is placing <div id="navbar" class="navbar-collapse collapse"> in row below <div class="navbar-header"> with floating and width it 100% of its space, then pulling up <ul class="nav navbar-nav navbar-right"> with margin-top: -50px;

通过该媒体查询,我们将确保它在moblie设备中正常运行.

With that media query we would sure it behave right in moblie device.

HTML

<div class="container-fluid">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="#">Logo/Brand</a>
  </div>
  <div id="navbar" class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
      <li><a href="#">LinkA</a></li>
      <li><a href="#">LinkB</a></li>
      <li><a href="#">LinkC</a></li>
      <li><a href="#">LinkD</a></li>
      <li><a href="#">LinkE</a></li>
    </ul>
    <ul class="nav navbar-nav navbar-right">
      <li><a href="#">Link1</a></li>
      <li><a href="#">Link2</a></li>
      <li><a href="#">Link3</a></li>
    </ul>
  </div><!--/.nav-collapse -->
</div>

CSS

.navbar-collapse {
    float: left;
    width: 100%;
    clear: both;
}

@media (min-width: 768px) {
    .navbar-right {
        margin-top: -50px;
    }
}

只是让我知道它是否有效.

JUST Let me know if it worked or not.

这篇关于创建具有两行的自适应Bootstrap导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆