如何让表单与导航按钮在同一行?

时间:2015-01-22 19:59:23

标签: html css html5 twitter-bootstrap twitter-bootstrap-3

我尝试过将缩进和放置放在不同的地方,但它仍然出现在导航按钮下方。我希望它在顶部的同一条线上。 我可能会试图让它在同一条线上变得有点混乱,如果是这样的话,只要在没有必要的情况下取出它。 `

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

<head>
    <meta charset="utf-8">
    <title>Bootstrap For Beginners</title>
    <meta name="description" content="Hello World">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">

<style>
    .nav {

    }
    .nav container-fluid {


    }
    .nav li {
        display: inline;
        padding: 20px;
        font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
    }

    .jumbotron {


    }
    .jumbotron container-fluid {

    }
    .jumbotron h1 {

    .footer {

    }
    .footer container-fluid {

    }
    .footer p {

    }

</style>

</head>

<body>
    <div class="nav">
        <div class="container-fluid">
            <ul class="nav nav-pills">
                <li class="pull-right"><a href="#">Contact</a></li>
                <li class="pull-right"><a href="#">About</a></li>
            </ul>

            <form class="form-horizontal">
                <div class="form-group">
                    <div class="col-md-6">
                        <input type="email" class="form-control" id="exampleInputEmail2" placeholder="Have Feedback?">
                    </div>
                    <div class="col-md-4">
                        <button type="submit" class="btn btn-default">Submit Feedback</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="jumbotron">
        <div class="container-fluid">
            <div class="row">
                <h1>Student</h1>
                <h1>Business</h1>
            </div>
        </div>
    </div>

    <div class="footer">
        <div class="container-fluid">
            <p>By:</p>
            <p>For:</p>
        </div>
    </div>

    <!-- Latest compiled and minified JavaScript -->
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</body> 
</html>

输入条似乎对真正小的窗口没有响应,这是正常的吗?

我还希望页脚与导航标题和jumbotron的大小相同,以填充其间的空间,所有内容都适合窗口而不滚动。

提前致谢。

3 个答案:

答案 0 :(得分:0)

要解决部分问题,请尝试将您想要并排的部分放在同一个div.row中,然后在每个部分周围包装div.col-xx-x。例如:

<div class="nav">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6 col-sm-6 col-xs-12">
                <ul class="nav nav-pills">
                    <li class="pull-right"><a href="#">Contact</a></li>
                    <li class="pull-right"><a href="#">About</a></li>
                </ul>
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12">
                <form class="form-horizontal">
                    <div class="form-group">
                        <div class="col-md-6">
                            <input type="email" class="form-control" id="exampleInputEmail2" placeholder="Have Feedback?">
                        </div>
                        <div class="col-md-4">
                            <button type="submit" class="btn btn-default">Submit Feedback</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

答案 1 :(得分:0)

我真的不确定你为什么不使用<navbar>课程。它就在那里,准备完成你正在寻找的东西。例如,请参阅此Bootply:

Bootply - Navbar

<nav class="navbar navbar-default">
  <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="#">Brand</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">
      </ul>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input class="form-control" placeholder="Have Feedback?" type="text">
        </div>
        <button type="submit" class="btn btn-default">Submit Feedback</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

有一种方法可以像你拥有它一样,但我不确定如何让<form><nav>类完美对齐,因为那里有填充它并从顶部向下移动一点。您可能需要一些自定义CSS来处理它。

Bootply - Original

<div class="container-fluid">
  <div class="row">
    <div class="col-xs-4">
      <form class="form-horizontal">
        <input class="form-control" id="exampleInputEmail2" placeholder="Have Feedback?" type="email">
      </form>
    </div>
    <div class="col-xs-2">
      <button type="submit" class="btn btn-default">Submit Feedback</button>
    </div>
    <div class="col-xs-6">
      <ul class="nav nav-pills">
        <li class="pull-right"><a href="#">Contact</a></li>
        <li class="pull-right"><a href="#">About</a></li>
      </ul>
    </div>
  </div>
</div>

让他们看看,看看是否适合你。

希望有所帮助!

答案 2 :(得分:0)

您的代码看起来很棒,您所要做的就是将表单和导航包装在包装器/容器中,然后使用col-md-6分隔这些部分。我在这里为你建立了一个例子http://www.bootply.com/P7VmPZOfXp

/* CSS used here will be applied after bootstrap.css */
.footer {
    height: 58px;
    background: #ccc;

  }
<div class="wrapper">
  <div class="container">
    <div class="row">
      <div class="container-fluid">

                    <div class="col-md-6 col-lg-6">
                                <form class="form-horizontal">
                                    <div class="form-group">
                                        <div class="col-md-6">
                                            <input class="form-control" id="exampleInputEmail2" placeholder="Have Feedback?" type="email">
                                        </div>
                                        <div class="col-md-4">
                                            <button type="submit" class="btn btn-default">Submit Feedback</button>
                                        </div>
                                    </div>
                                </form><!-- .form-horizontal -->
                    </div><!-- .col-6 -->

                      <div class="col-md-6 col-lg-6">
                            <div class="nav">
                                <ul class="nav nav-pills">
                                    <li class="pull-right"><a href="#">Contact</a></li>
                                    <li class="pull-right"><a href="#">About</a></li>
                                </ul>
                            </div><!-- .nav -->
                        </div><!-- .col-6 -->

        </div><!-- .fluid container -->
    </div><!-- .row -->
</div><!-- .container-->
</div><!-- .wrapper-->
    <div class="jumbotron">
        <div class="container-fluid">
            <div class="row">
                <h1>Student</h1>
                <h1>Business</h1>
            </div>
        </div>
    </div><!-- .jumbotron -->

    <div class="footer">
        <div class="container-fluid">
            <p>By:</p>
            <p>For:</p>
        </div>
    </div><!-- .footer -->