css - 两层 Bootstrap 3 导航

标签 css twitter-bootstrap twitter-bootstrap-3

创建我在下面绘制的 Bootstrap 3 导航栏的最佳方法是什么?

enter image description here

我希望 Logo 具有全高,并且底部的蓝色键具有 45 度 Angular 。顶部导航栏将只包含社交媒体的很棒的字体图标。

最佳答案

这是实现此目的的一种方法:将导航栏链接包装在新的 div 中,同时将图标链接(上部)与文本链接(下部)分开,以便它们仍然可以使用默认的移动切换功能。

然后,您可以通过向一个部分添加 width: 100% 来简单地在上下部分之间创建分割。

就下部导航部分的有 Angular 部分而言,您可以使用带有边框规则的伪元素来实现此目的:请参阅 MDN了解更多信息。

这里有两个示例,具体取决于您最终想要执行的操作:一个是全 Angular ,另一个是在容器内。

示例 2:全 Angular

.navbar.navbar-inverse {
  border: none;
}
.navbar.navbar-inverse .navbar-split ul > li > a {
  color: #fff;
}
@media (min-width: 768px) {
  .navbar.navbar-inverse .navbar-split {
    position: relative;
    padding-left: 50px;
    float: right;
    margin-right: -15px;
  }
  .navbar.navbar-inverse .navbar-split:before {
    position: absolute;
    left: 0;
    top: 50px;
    content: '';
    border-bottom: 50px solid #069CCF;
    border-left: 50px solid transparent;
  }
  .navbar.navbar-inverse .navbar-split:after {
    position: absolute;
    left: 0;
    top: 50px;
    content: '';
    border-bottom: 50px solid #069CCF;
    border-left: 50px solid transparent;
  }
  .navbar.navbar-inverse .navbar-split .navbar-upper {
    padding-left: 0;
    float: right;
  }
  .navbar.navbar-inverse .navbar-split .navbar-lower {
    background-color: #069CCF;
    width: 100%;
    clear: both;
  }
}
@media (max-width: 767px) {
  .navbar.navbar-inverse {
    padding: 20px 0;
  }
  .navbar.navbar-inverse .navbar-brand {
    padding-top: 0;
    margin-top: -10px;
  }
  .navbar.navbar-inverse .navbar-collapse {
    margin-top: 15px;
    margin-bottom: -15px;
    border: none;
    box-shadow: none;
  }
  .navbar.navbar-inverse .navbar-upper {
    display: table;
    width: 100%;
    text-align: center;
    margin: 0;
    padding: 10px 0;
  }
  .navbar.navbar-inverse .navbar-upper > li {
    display: table-cell;
    font-size: 32px;
  }
  .navbar.navbar-inverse .navbar-lower {
    padding: 0 0 15px;
    margin: 0;
    text-align: center;
  }
  .navbar.navbar-inverse .navbar-lower > li > a {
    font-size: 24px;
    padding: 15px 0;
  }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  <div class="container-fluid">

    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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="#">
        <img src="https://placehold.it/70x70/FA05D5/fff">
      </a>
    </div>

    <div class="collapse navbar-collapse" id="navbar">
      <div class="navbar-split">
        <ul class="nav navbar-nav navbar-upper">
          <li><a href="#"><i class="fa fa-facebook"></i></a>
          </li>
          <li><a href="#"><i class="fa fa-twitter"></i></a>
          </li>
          <li><a href="#"><i class="fa fa-instagram"></i></a>
          </li>
          <li><a href="#"><i class="fa fa-youtube"></i></a>
          </li>
        </ul>
        <ul class="nav navbar-nav navbar-lower">
          <li><a href="#">ABOUT</a>
          </li>
          <li><a href="#">SERVICES</a>
          </li>
          <li><a href="#">CONTACT</a>
          </li>
        </ul>
      </div>
    </div>

  </div>
</nav>

<div class="container">
  <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a
    galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets
    containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the
    printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
    but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker
    including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
    it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
    and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since
    the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
    the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting
    industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic
    typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem
    Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
    took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
    sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  </p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

示例 2:容器宽度

.navbar.navbar-inverse {
  border: none;
}
.navbar.navbar-inverse .navbar-split ul > li > a {
  color: #fff;
}
@media (min-width: 768px) {
  .navbar.navbar-inverse .navbar-split {
    position: relative;
    padding-left: 50px;
    float: right;
    margin-right: -15px;
  }
  .navbar.navbar-inverse .navbar-split:before {
    position: absolute;
    left: 0;
    right: 0;
    top: 50px;
    content: '';
    border-bottom: 50px solid #069CCF;
    border-left: 50px solid transparent;
  }
  .navbar.navbar-inverse .navbar-split:after {
    position: absolute;
    left: 0;
    right: 100%;
    top: 50px;
    content: '';
    border-bottom: 50px solid #069CCF;
    border-left: 50px solid transparent;
  }
  .navbar.navbar-inverse .navbar-split .navbar-upper {
    float: right;
  }
  .navbar.navbar-inverse .navbar-split .navbar-lower {
    background-color: #069CCF;
    width: 100%;
    clear: both;
  }
}
@media (max-width: 767px) {
  .navbar.navbar-inverse {
    padding: 20px 0;
  }
  .navbar.navbar-inverse .navbar-brand {
    padding-top: 0;
    margin-top: -10px;
  }
  .navbar.navbar-inverse .navbar-collapse {
    margin-top: 15px;
    margin-bottom: -15px;
  }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
  <div class="container">

    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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="#">
        <img src="https://placehold.it/70x70/FA05D5/fff">
      </a>
    </div>

    <div class="collapse navbar-collapse" id="navbar">
      <div class="navbar-split">
        <ul class="nav navbar-nav navbar-upper">
          <li><a href="#"><i class="fa fa-facebook"></i></a>
          </li>
          <li><a href="#"><i class="fa fa-twitter"></i></a>
          </li>
          <li><a href="#"><i class="fa fa-instagram"></i></a>
          </li>
          <li><a href="#"><i class="fa fa-youtube"></i></a>
          </li>
        </ul>
        <ul class="nav navbar-nav navbar-lower">
          <li><a href="#">ABOUT</a>
          </li>
          <li><a href="#">SERVICES</a>
          </li>
          <li><a href="#">CONTACT</a>
          </li>
        </ul>
      </div>
    </div>

  </div>
</nav>

<div class="container">
  <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a
    galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets
    containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the
    printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
    but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker
    including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
    it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
    and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since
    the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in
    the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting
    industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic
    typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem
    Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
    took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
    sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
    standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  </p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

关于css - 两层 Bootstrap 3 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38277123/

相关文章:

html - 尝试为网站创建 css 样式(Bootstrap)

javascript - jQuery。如何将 JS 变量与标签文字结合起来?

html - 移动 View 中的文本重叠

css - 如何用纯css凹出一条直线

javascript - 尝试打印页面时如何隐藏导航栏

html - 内容在移动设备上没有响应(Bootstrap)

javascript - 将变量从 link_to 传递到 Rails 中的模态

javascript - 列表中包含的 div 自动淡入淡出

css - 带有指向上次查看页面的链接的 float 按钮

twitter-bootstrap - Bootstrap 4 居中导航栏