分离引导按钮

时间:2014-09-29 22:06:23

标签: html twitter-bootstrap-3

我想复制我的“提交”按钮。当我这样做时,似乎bootstrap认为复制是导航栏的一部分,所以当我做style =“margin-top:30px;”导航栏基本上会增长,直到它到达按钮。亲自看看:http://jsfiddle.net/aqs2z6oo/我想知道如何只取这个按钮并使其成为自己的按钮,这样我就可以在页面中移动它。我尝试了一些事情,比如将按钮形式放在容器和行div中,但它们似乎不起作用。

  <a class="navbar-brand" href="#"><img src="img/logo.png" style="position: relative; top: -7.5px;" /></a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav">
    <li class="active"><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated linkk</a></li>
      </ul>
    </li>
  </ul>
  <form class="navbar-form navbar-left" role="search">
    <div class="form-group">
      <input type="text" class="form-control" placeholder="Search" size=60px>
    </div>
    <button type="submit" class="btn btn-default" value="Open Window" onclick="window.open('http://www.cnn.com')">Submit</button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
      </ul>
    </li>
  </ul>
</div><!-- /.navbar-collapse -->

        提交

1 个答案:

答案 0 :(得分:1)

您只是忘了添加结束nav HTML标记(看起来像这样:</nav>)。您的代码(基于JsFiddle)如下:

<!-- Your Navbar starts here -->
<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 collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <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="img/logo.png" style="position: relative; top: -7.5px;" /></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li class="divider"></li>
            <li><a href="#">One more separated linkk</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search" size=60px>
        </div>
        <button type="submit" class="btn btn-default" value="Open Window" onclick="window.open('http://www.cnn.com')">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav><!-- /.your navbar ends here -->

<!-- Here's your submit button, seperated from the navbar -->
<form style="margin-top: 400px;">
  <button type="button" class="btn btn-default" value="Open Window" onclick="window.open('http://www.cnn.com')">Submit</button>
</form>

将来避免此类问题的简单方法是使用BracketsAtomSublime Text等文本编辑器,每个文本编辑器都会显示您的开始标记与结束标记相关联。不过不用担心,我知道我一直都会犯这样的错误!

这是更新的JSFiddle