如何使内联表单引导中心3

时间:2014-09-29 14:59:56

标签: html css twitter-bootstrap-3

我正在尝试制作一个包含多个选项的搜索栏,并希望将其置于中心位置



<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<div id="search_panel">
  <div class='container'>
    <form class="form-inline" role="form">
      <!-- SEARCH PLACE -->
      <div class="form-group">
        <label class="sr-only" for="inputEmail">search</label>
        <input id="where" name="where" type="search" placeholder="where you want to visit ...." class="form-control input-md" required="">
      </div>
      <!-- CHECK-IN DATE -->
      <div class="form-group" id="start">
        <i class="fa fa-calendar fa-2x"></i>
        <input type='text' placeholder="Check-In Date" class="form-control" id='datepicker-start' />
      </div>
      <div class="form-group" id="end">
        <i class="fa fa-calendar fa-2x"></i>
        <input type='text' placeholder="Check-Out Date" class="form-control" id='datepicker-end' />
      </div>
      <!-- Button Drop Down -->
      <div class="form-group">
        <label class="sr-only" for="inputEmail">Select Basic</label>
        <select id="selectbasic" name="selectbasic" class="form-control">
          <option value="1">Option one</option>
          <option value="2">Option two</option>
        </select>
      </div>
    </form>
  </div>
</div>
&#13;
&#13;
&#13;

5 个答案:

答案 0 :(得分:10)

你也可以组合课程

如果你改变你的定义

<form class="form-inline" role="form">

要  <form class="form-inline text-center" role="form"> 它应该工作!

我希望在添加额外样式之前尽可能保持简单的引导程序

和bootstrap带有原生对齐类,可在此处找到:http://getbootstrap.com/css/#type-alignment

HTH

答案 1 :(得分:7)

我会尝试将text-align: center添加到表单中。请参阅我的示例(请注意,要查看效果,您必须选择&#34;完整页面&#34;否则,bootsrap默认为移动视图。)

编辑:

糟糕!我想你不需要inline-block。无论如何,我有inline-bock。 :P

&#13;
&#13;
#search_panel {
    text-align: center;	
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<div id="search_panel">
  <div class='container'>
    <form class="form-inline" role="form">
      <!-- SEARCH PLACE -->
      <div class="form-group">
        <label class="sr-only" for="inputEmail">search</label>
        <input id="where" name="where" type="search" placeholder="where you want to visit ...." class="form-control input-md" required="">
      </div>
      <!-- CHECK-IN DATE -->
      <div class="form-group" id="start">
        <i class="fa fa-calendar fa-2x"></i>
        <input type='text' placeholder="Check-In Date" class="form-control" id='datepicker-start' />
      </div>
      <div class="form-group" id="end">
        <i class="fa fa-calendar fa-2x"></i>
        <input type='text' placeholder="Check-Out Date" class="form-control" id='datepicker-end' />
      </div>
      <!-- Button Drop Down -->
      <div class="form-group">
        <label class="sr-only" for="inputEmail">Select Basic</label>
        <select id="selectbasic" name="selectbasic" class="form-control">
          <option value="1">Option one</option>
          <option value="2">Option two</option>
        </select>
      </div>
    </form>
  </div>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:2)

只需将 .text-center 类添加到包含该表单的行

即可

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta charset="utf-8">
<!-- meta http-equiv="X-UA-Compatible" content="IE=edge" -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
  </head>
  <body>
<div class="container-fluid" style="background-color: #EEEEEE;">
  <div class="row text-center">
    <div class="col-sm-12" id="formContainer">
      <form class="form-inline" id="SignToNewsletterForm" onsubmit="...">
        <input type="text" class="form-control input-lg" id="firstname" placeholder="Your first name...">
        <input type="email" class="form-control input-lg" id="email" placeholder="Your Email Address...">
        <button type="submit" class="btn btn-success btn-lg">I Want To Subscribe</button>
      </form>
    </div>
  </div>
</div>
  </body>
</html>

答案 3 :(得分:1)

我不确定我是否理解了您的问题,但这里是一个以表格为中心的示例:

http://jsfiddle.net/Lfw3v0p6/

我只是添加了一些CSS:

.form-inline {
    text-align: center;
}

如果这不是您正在寻找的内容,请更新您的问题以提供更多详细信息或您尝试过的示例。

答案 4 :(得分:0)

#search_panel {
    text-align: center; 
    z-index:10;
    position:absolute;
    padding-left:5%;
    top:40%;
}

当我确定位置是绝对的所有填充消失时,我给出了左边填充的原因