全宽响应等间距水平菜单栏引导3

时间:2014-05-28 09:01:32

标签: jquery css html5 responsive-design twitter-bootstrap-3

嗨我有这样的菜单栏

这是我的HTML

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Business Casual Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- Add custom CSS here -->
    <link href="css/business-casual.css" rel="stylesheet">
</head>

<body>




    <nav class="navbar navbar-default" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <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="index.html">Info Dubai</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav">
              <li><a href="#"><span><img src="images/todoBtn.png"></span>&nbsp;&nbsp;ToDo</a></li>
              <li><a href="#"><span><img src="images/dineBtn.png"></span>&nbsp;&nbsp;Dining</a></li>
              <li><a href="#"><span><img src="images/shopBtn.png"></span>&nbsp;&nbsp;Shooping</a></li>
              <li><a href="#"><span><img src="images/todoBtn.png"></span>&nbsp;&nbsp;NightLife</a></li>
              <li><a href="#"><span><img src="images/fashionBtn.png"></span>&nbsp;&nbsp;Fashion</a></li>
              <li><a href="#"><span><img src="images/bodyBtn.png"></span>&nbsp;&nbsp;Body&Mind </a></li>
              <li><a href="#"><span><img src="images/eventBtn.png"></span>&nbsp;&nbsp;Events</a></li>
              <li><a href="#"><span><img src="images/exclusiveBtn.png"></span>&nbsp;&nbsp;Exclusive</a></li>
              <li><a href="#"><span><img src="images/tarvelBtn.png"></span>&nbsp;&nbsp;Travel</a></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>


    <!-- /.container -->



    <!-- JavaScript -->
    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/bootstrap.js"></script>

</body>

</html>

这里是css

hr {
  border-color: #999999;
  max-width: 400px;
}

.brand,
.address-bar {
  display: none;
}


.navbar-brand {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 900;
}

.navbar-nav {
  text-transform: none;
  letter-spacing: 0px;
  font-weight:bold;
}

.img-full {
  min-width: 100%;
}

.brand-name {
  font-weight: 700;
  font-size: 1.5em;
  text-transform: capitalize;
  letter-spacing: normal;
}

.tagline-divider {
  margin: 15px auto 3px;
  border-color: #999999;
  max-width: 250px;
}

.box {
  background: #fff;
  background: rgba(255,255,255,0.9);
  margin-bottom: 20px;
  padding: 30px 15px;
}

.intro-text {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 1.25em;
  font-weight: 400;
}

.img-border {
  float: none;
  margin: 0 auto 0;
  border: #999999 solid 1px;
}

.img-left {
  float: none;
  margin: 0 auto 0;
}

footer {
  background: #fff;
  background: rgba(255,255,255,0.9);
}

footer p {
  margin: 0;
  padding: 50px 0;
}

@media screen and (min-width: 768px) {

.brand {
  display: inherit;
  font-weight: 700;
  font-size: 5em;
  line-height: normal;
  text-align: center;
  margin: 0;
  padding: 30px 0 10px;
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.top-divider {
  margin-top: 0;
}

.img-left {
  float: left;
  margin-right: 25px;
}

.address-bar {
  display: inherit;
  text-align: center;
  margin: 0;
  padding: 0 0 40px;
  font-size: 1.25em;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 400;
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.navbar {
  border-radius: 0;
}

.navbar-header {
  display: none;
}

.navbar {
  min-height: 0;
}

.navbar-default {
  background:#FFF;
  background: #323132;
  border: none;
}

.nav>li>a {
  /*padding: 35px;*/
}

.navbar-nav>li>a {
  line-height:normal;
}

.navbar-nav {
  float: none;
  margin: 0 auto;
  display: table;
  table-layout: fixed;
  font-size: 0.99em;
}

}

@media screen and (min-width: 1200px) {
    .box:after {
        content: '';
        display: table;
        clear: both;
    }
}
.navbar-default .navbar-nav > li > a {
    color:#FFF;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
  color: #FFF !important;
  background-color: #DD9B26 !important;
}
.navbar-default .navbar-toggle {
  border-color: #ddd !important;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
  background-color: #999 !important;
}
.navbar-default .navbar-toggle .icon-bar {
  background-color: #CCC !important;
}
.navbar-collapse {
  max-height: 340px;
  padding-right: 15px;
  padding-left: 15px;
  overflow-x: visible;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
  background-color:#323132;
}
.navbar-default .navbar-collapse, .navbar-default .navbar-form {
    border-color: transparent;
}

但我想要这种菜单栏 ![在此输入图像说明] [2] 但没有成功。如果有任何身体有想法或技巧,我想制作全宽等空间li水平菜单栏请与我分享 响应

1 个答案:

答案 0 :(得分:0)

我理解你的问题是你想让每个导航链接的宽度相等,并跨越浏览器的整个宽度。如果这是正确的,您可以使用此示例生成等宽导航链接:http://getbootstrap.com/examples/justified-nav/#

要使导航跨越浏览器的整个宽度,您需要将容器更改为容器流体。在上面的示例中,这意味着用<div class="container">替换<body>标记下方的<div class="container-fluid">

使用你拥有的东西,以便你也可以获得切换效果:

  1. <div class="container">更改为<div class="container-fluid nav-container">
  2. 然后,您需要在媒体查询中添加规则,以从容器中删除填充 - 流体ABOVE 768px
  3. 然后,您需要将导航链接的宽度设置为每个11.1111%(100%/ 9)。同样,您必须在媒体查询中为min-width:768px
  4. 执行此操作
  5. 接下来,您需要将同一媒体查询中navbar-nav类的宽度设置为100%
  6. 最后,删除您在媒体查询中向左和向右添加的填充为1200px及以上,并在媒体查询中将其设置为0,以获得最小宽度:768px
  7. 所以,你的CSS会看起来像这样。请注意,您必须使用字体大小或图像才能使所有菜单项整齐地放在一行上,如果这是您想要的所有屏幕宽度。在我的屏幕上,一些链接开始突破到1228px的下一行!

    hr {
      border-color: #999999;
      max-width: 400px;
    }
    
    .brand,
    .address-bar {
      display: none;
    }
    
    
    .navbar-brand {
      text-transform: uppercase;
      letter-spacing: 2px;
      font-weight: 900;
    }
    
    .navbar-nav {
      text-transform: none;
      letter-spacing: 0px;
      font-weight:bold;
    }
    
    .img-full {
      min-width: 100%;
    }
    
    .brand-name {
      font-weight: 700;
      font-size: 1.5em;
      text-transform: capitalize;
      letter-spacing: normal;
    }
    
    .tagline-divider {
      margin: 15px auto 3px;
      border-color: #999999;
      max-width: 250px;
    }
    
    .box {
      background: #fff;
      background: rgba(255,255,255,0.9);
      margin-bottom: 20px;
      padding: 30px 15px;
    }
    
    .intro-text {
      text-transform: uppercase;
      letter-spacing: 1px;
      font-size: 1.25em;
      font-weight: 400;
    }
    
    .img-border {
      float: none;
      margin: 0 auto 0;
      border: #999999 solid 1px;
    }
    
    .img-left {
      float: none;
      margin: 0 auto 0;
    }
    
    footer {
      background: #fff;
      background: rgba(255,255,255,0.9);
    }
    
    footer p {
      margin: 0;
      padding: 50px 0;
    }
    
    @media screen and (min-width: 768px) {
    
    .nav-container {padding: 0;}
    .navbar-nav>li {width: 11.111111%;}
    .navbar-nav {width: 100%;}
    .navbar-collapse {padding: 0;}
    
    .brand {
      display: inherit;
      font-weight: 700;
      font-size: 5em;
      line-height: normal;
      text-align: center;
      margin: 0;
      padding: 30px 0 10px;
      color: #fff;
      text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    }
    
    .top-divider {
      margin-top: 0;
    }
    
    .img-left {
      float: left;
      margin-right: 25px;
    }
    
    .address-bar {
      display: inherit;
      text-align: center;
      margin: 0;
      padding: 0 0 40px;
      font-size: 1.25em;
      text-transform: uppercase;
      letter-spacing: 3px;
      font-weight: 400;
      color: #fff;
      text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    }
    
    .navbar {
      border-radius: 0;
    }
    
    .navbar-header {
      display: none;
    }
    
    .navbar {
      min-height: 0;
    }
    
    .navbar-default {
      background:#FFF;
      background: #323132;
      border: none;
    }
    
    .nav>li>a {
      /*padding: 35px;*/
    }
    
    .navbar-nav>li>a {
      line-height:normal;
    }
    
    .navbar-nav {
      float: none;
      margin: 0 auto;
      display: table;
      table-layout: fixed;
      font-size: 0.99em;
    }
    
    }
    
    @media screen and (min-width: 1200px) {
        .box:after {
            content: '';
            display: table;
            clear: both;
        }
    }
    .navbar-default .navbar-nav > li > a {
        color:#FFF;
    }
    .navbar-default .navbar-nav > li > a:hover,
    .navbar-default .navbar-nav > li > a:focus {
      color: #FFF !important;
      background-color: #DD9B26 !important;
    }
    .navbar-default .navbar-toggle {
      border-color: #ddd !important;
    }
    .navbar-default .navbar-toggle:hover,
    .navbar-default .navbar-toggle:focus {
      background-color: #999 !important;
    }
    .navbar-default .navbar-toggle .icon-bar {
      background-color: #CCC !important;
    }
    .navbar-collapse {
      max-height: 340px;
      overflow-x: visible;
      -webkit-overflow-scrolling: touch;
      border-top: 1px solid transparent;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
      background-color:#323132;
    }
    .navbar-default .navbar-collapse, .navbar-default .navbar-form {
        border-color: transparent;
    }