Bootstrap 3 Navbar切换 - 折叠但不显示按钮

时间:2014-02-12 16:38:10

标签: javascript jquery html css twitter-bootstrap

我不知道我在这里做错了什么,但我认为这是一件非常愚蠢的事。

我在Umbraco 6.0.5中使用Bootstrap 3并且我无法让切换工作调整大小 - 导航器折叠的宽度低于770px但是没有按钮可以切换它,或者更确切地说是存在的东西,如代码和Firebug,但在Chrome和Firefox中不可见(尚未尝试IE)。

有一个fiddle和下面的代码。我在小提琴中使用http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.jshttp://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.jshttp://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css

<nav class="navbar">
  <div class="container-fluid">
    <div class="navbar-header">

      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-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"#">reech</a>  
    </div>

    <div class="collapse navbar-collapse" id="nav-collapse">
      <ul class="nav navbar-nav">
        <li><a href="/" class="selected">Home</a></li>
        <li class=" dropdown">
          <a href="/what-is-reech.aspx" class=" dropdown-toggle" data-hover="dropdown" rel="">What is reech? <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="/what-is-reech/about-this-site.aspx" rel="">About this site</a></li>
          </ul>
        </li>
        <li class=" dropdown">
        </li>
        <li><a href="/key-reech-projects.aspx" class="" rel="">Key reech projects</a></li> 
        <li class=" dropdown">
        </li>
        <li><a href="/technologies.aspx" class="" rel="">Technologies</a></li> 
        <li class=" dropdown">
        </li>
        <li><a href="/complementary-activities.aspx" class="" rel="">Complementary Activities</a></li> 
        <li class=" dropdown">
          <a href="/news.aspx" class=" dropdown-toggle" data-hover="dropdown" rel="">News <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="/news/merseyside-collective-switching-scheme-launched.aspx" rel="">Merseyside collective switching scheme launched</a></li>
            <li><a href="/news/reech-scoops-top-award.aspx" rel="">reech scoops top award</a></li>
            <li><a href="/news/reech-award-nomination.aspx" rel="">reech award nomination</a></li>
            <li><a href="/news/green-deal-and-energy-company-obligation-(eco)-september-2013-statistics.aspx" rel="">Green Deal and Energy Company Obligation (ECO) September 2013 Statistics</a></li>
            <li><a href="/news/energy-switching-scheme.aspx" rel="">Energy Switching Scheme</a></li>
            <li><a href="/news/project-reeches-new-milestone.aspx" rel="">Project &#39;reeches&#39; new milestone</a></li>
            <li><a href="/news/firms-sign-up-for-new-opportunities.aspx" rel="">Firms sign up for new opportunities</a></li>
            <li><a href="/news/14-new-jobs-created-for-merseyside-residents.aspx" rel="">14 new jobs created for Merseyside residents</a></li>
            <li><a href="/news/reeching-out-to-low-carbon-and-green-energy-sector.aspx" rel="">&#39;reeching&#39; out to Low Carbon and Green Energy Sector</a></li>
          </ul>
        </li>
        <li class=" dropdown">
        </li>
        <li><a href="/reech-into-business.aspx" class="" rel="">reech into business</a></li> 
        <li class=" dropdown">
          <a href="/reech-partners.aspx" class=" dropdown-toggle" data-hover="dropdown" rel="">reech partners <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="/reech-partners/reech-steering-group.aspx" rel="">reech Steering Group</a></li>
          </ul>
        </li>

      </ul>
    </div><!--close navbar-collapse-->
  </div><!--close container-->
</nav><!--Close nav-->

更新 - 所以,我尝试将数据目标(并将fiddle更改为)改为#main-nav,将id更改为main-nav,没有任何乐趣。 我尝试在按钮中添加一个破折号字符&gt; span元素,它的工作原理。也就是说,破折号显示,我可以切换菜单。但是图标栏在哪里?

  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-nav">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar">-</span>
    <span class="icon-bar">-</span>
    <span class="icon-bar">-</span>
  </button>

4 个答案:

答案 0 :(得分:34)

<nav class="navbar">更改为<nav class="navbar navbar-default">

答案 1 :(得分:7)

Bootstrap - 切换按钮不会在移动视图中显示

FIX: 在以下位置进行以下更改:bootstrap.min.css

这会修复切换按钮的外边框

.navbar-toggle
{
    position:relative;
    float:right;
    padding:9px 10px;
    margin-top:8px;
    margin-right:15px;
    margin-bottom:8px;
    background-color:transparent;
    background-image:none;
    border-radius:4px
}

添加

border:1px solid #444;

(更改颜色代码以符合您的设计)

.navbar-toggle
{
    position:relative;
    float:right;
    padding:9px 10px;
    margin-top:8px;
    margin-right:15px;
    margin-bottom:8px;
    background-color:transparent;
    background-image:none;
    border:1px solid #444;          /* added line */
    border-radius:4px
}

这会修复切换按钮的水平线

.icon-bar
{
    display:block;
    width:22px;
    height:2px;
    border-radius:1px;
}

添加

border:1px solid #444;

(更改颜色代码以符合您的设计)

.icon-bar
{
    display:block;
    width:22px;
    height:2px;
    border-radius:1px;
    border:1px solid #444;
}

答案 2 :(得分:3)

这应该让你指出正确的方向。看起来你的主要打嗝是你的按钮数据目标属性是引用一个类而不是一个ID。在这种情况下最好使用ID,所以如果你在代码中的其他地方调用那个类,你就不会在javascript中抛出曲线球。

我也看到你有几个<li class="dropdown"></li>是空白的。我不确定这是否是故意的,但我会参考我所附的结构。

希望这对你有用,祝你好运!

<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid"> 
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-nav"> <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="#">Reech</a> </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="main-nav">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li class="dropdown"> <a href="/what-is-reech.apsx" class="dropdown-toggle" data-toggle="dropdown">What is reech? <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="/what-is-reech/about-this-site-aspx">About this site</a></li>
          </ul>
        </li><!-- dropdown -->
        <li class="dropdown"> <a href="/what-is-reech.apsx" class="dropdown-toggle" data-toggle="dropdown">Key reech projects <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="/technologies.apsx">Technologies</a></li>
            <li><a href="/complementary-activities.apsx">Complementary Activities</a></li>
          </ul>
        </li><!-- dropdown -->
        <li class="dropdown"> <a href="/what-is-reech.apsx" class="dropdown-toggle" data-toggle="dropdown">Key reech projects <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="/technologies.apsx">Technologies</a></li>
          </ul>
        </li><!-- dropdown -->
      </ul><!-- nav navbar-nav -->
    </div><!-- collapse navbar-collapse -->
    <!-- /.navbar-collapse --> 
  </div>
  <!-- /.container-fluid --> 
</nav>

答案 3 :(得分:2)

在第1行

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">

它应为data-target="#nav-collapse",因为您有<div class="collapse navbar-collapse" id="nav-collapse">,其中ID为nav-collapse