Bootstrap nav-tabs全宽

时间:2016-12-20 12:46:47

标签: html css twitter-bootstrap

我使用绝对定位在容器底部定位了bootstrap nav-tabs,并且它在一个问题上工作得非常好:一旦我定位绝对,它就不再是容器的全宽度了。 这是一张图片:

enter image description here

HTML:

<div class="container-fluid">
  <ul class="nav nav-tabs profile-nav">
    <li class="nav-item">
      <a class="nav-link active" href="#">Active</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
    </li>
    <li class="nav-item">
      <a class="nav-link disabled" href="#">Disabled</a>
    </li>
  </ul>
</div>

CSS:

.profile-nav{
  position: absolute;
  bottom: 0;
  transform: translateY(50%);
  background-color: #fff;
  box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.15);
}

.profile-nav .nav-item{
  padding-top: 15px;
  padding-bottom: 15px;
}

图像容器具有位置:relative,以便像那样定位导航。 所以,正如我所说,问题是,我无法使其成为容器流体的全宽。

3 个答案:

答案 0 :(得分:0)

添加irb(main):001:0> s = "A123" # Create string to split. => "A123" irb(main):002:0> a, b = s.split(/\d/) # Extracts letter only. => ["A"] irb(main):003:0> puts a # a got assigned 'A' as expected. A => nil irb(main):004:0> puts b # b did not get assigned the split remainder, '123'. => nil irb(main):005:0> b = s.split(/\D/) # Extracts number only. => ["", "123"] irb(main):006:0> puts b # Now b has the value I want it to have. 123 => nil &amp; left: 0;width: 100%;

.profile-nav
.profile-nav {
  position: absolute;
  bottom: 0;
  transform: translateY(50%);
  background-color: #fff;
  box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.15);
  /* add these */
  width: 100%;
  left: 0;
}

.profile-nav .nav-item {
  padding-top: 15px;
  padding-bottom: 15px;
}

答案 1 :(得分:0)

试试这个,可能会有所帮助

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
  .profile-nav {
  position: absolute;
  bottom: 0;
  transform: translateY(50%);
  background-color: #eee;
  box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.15);
  /* add these */
  width: 100%;
  left: 0;
}

.profile-nav .nav-item {
  padding-top: 15px;
  padding-bottom: 15px;
}
  </style>
</head>
<body>

<div class="container-fluid">
  <ul class="nav nav-tabs profile-nav">
    <li class="nav-item">
      <a class="nav-link active" href="#">Active</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
    </li>
    <li class="nav-item">
      <a class="nav-link disabled" href="#">Disabled</a>
    </li>
  </ul>
</div>
  
<div class="container-fluid">
  <h3>Basic Navbar Example</h3>
  <p>A navigation bar is a navigation header that is placed at the top of the page.</p>
</div>

</body>
</html>

答案 2 :(得分:0)

要修复导航标签的底部,您需要使用引导程序类navbar-fixed-bottom

将项目包装到导航栏中
<nav class="navbar navbar-default navbar-fixed-bottom profile-nav">

我认为nav-tabs不是最适合底层菜单的形式。请尝试使用nav-pills

看一下片段

.profile-nav {
  background-color: #fff;
  box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.15);
  border: none;
}

.profile-nav .nav-item {
  padding-top: 15px;
  padding-bottom: 15px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-bottom profile-nav">
 <div class="container-fluid">
   <ul class="nav nav-pills">
    <li class="nav-item">
      <a class="nav-link active" href="#">Active</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link</a>
    </li>
    <li class="nav-item">
      <a class="nav-link disabled" href="#">Disabled</a>
    </li>
  </ul>
 </div>
</nav>