How to center the built-in bootstrap form 3

I am trying to create a search bar with several parameters and want to center it.

<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>
Run codeHide result
+4
source share
5 answers

I would try adding text-align: centerto the form. See My example (note that to view the effect you need to select β€œFull Page.” Otherwise, bootsrap is used by default for mobile viewing).

Edit:

oops! I think you do not need inline-block. Anyway, I had it like inline-bock.: P

#search_panel {
    text-align: center;	
}
<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>
Run codeHide result
+7
source

you can also combine classes

if you change your definition from

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

 <form class="form-inline text-center" role="form"> !

,

bootstrap , : http://getbootstrap.com/css/#type-alignment

+7

.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>
Hide result
+2

, , :

http://jsfiddle.net/Lfw3v0p6/

CSS:

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

, , , , .

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

, , ,

0

All Articles