Koray
Koray

Reputation: 1

Bootstrap 3 form element side by side and combined

i have 2 tab and 2 form. In secondly tab everything is good but i have need help for first tab. In first tab one select menu, one text input and one button. I want this 3 element side by side and combined, thanks for help...

My codes..

<!DOCTYPE html>
<html lang="en">
   <head>
      <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 -->
      <title>Bootstrap Tab</title>
      <!-- Bootstrap -->
      <!-- Latest compiled and minified CSS -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
      <!-- Optional theme -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" 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.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
      <![endif]-->
      <style type="text/css">
         .panel.with-nav-tabs .panel-heading{
         padding: 5px 5px 0 5px;
         }
         .panel.with-nav-tabs .nav-tabs{
         border-bottom: none;
         }
         .panel.with-nav-tabs .nav-justified{
         margin-bottom: -1px;
         }
         /********************************************************************/
         /*** PANEL DEFAULT ***/
         .with-nav-tabs.panel-default .nav-tabs > li > a,
         .with-nav-tabs.panel-default .nav-tabs > li > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li > a:focus {
         color: #777;
         }
         .with-nav-tabs.panel-default .nav-tabs > .open > a,
         .with-nav-tabs.panel-default .nav-tabs > .open > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > .open > a:focus,
         .with-nav-tabs.panel-default .nav-tabs > li > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li > a:focus {
         color: #777;
         background-color: #ddd;
         border-color: transparent;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.active > a,
         .with-nav-tabs.panel-default .nav-tabs > li.active > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li.active > a:focus {
         color: #555;
         background-color: #fff;
         border-color: #ddd;
         border-bottom-color: transparent;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu {
         background-color: #f5f5f5;
         border-color: #ddd;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a {
         color: #777;   
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
         background-color: #ddd;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a,
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
         color: #fff;
         background-color: #555;
         }
      </style>
   </head>
   <body>
      <div class="col-md-6 col-md-offset-3">
         <div class="panel with-nav-tabs panel-default">
            <div class="panel-heading">
               <ul class="nav nav-tabs">
                  <li class="active"><a href="#tab1default" data-toggle="tab">Arama 1</a></li>
                  <li><a href="#tab2default" data-toggle="tab">Arama 2</a></li>
               </ul>
            </div>
            <div class="panel-body">
               <div class="tab-content">
                  <div class="tab-pane fade in active" id="tab1default">
                     <div class="input-group">
                        <select class="form-control">
                           <option value="ist">istanbul</option>
                           <option value="ank">ankara</option>
                           <option value="izm">izmir</option>
                           <option value="adn">adana</option>
                        </select>
                        <input type="text" class="form-control">
                        <span class="input-group-btn">
                        <button class="btn btn-default" type="button">Go!</button>
                        </span>
                     </div>
                     <!-- /input-group -->
                  </div>
                  <div class="tab-pane fade" id="tab2default">
                     <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search for...">
                        <span class="input-group-btn">
                        <button class="btn btn-default" type="button">Go!</button>
                        </span>
                     </div>
                     <!-- /input-group -->
                  </div>
               </div>
            </div>
         </div>
      </div>
      <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
   </body>
</html>

Upvotes: 0

Views: 1130

Answers (3)

Asons
Asons

Reputation: 87191

With the existing markup, adding a <span class="input-group-btn" style="width:0px;"></span> between the select and input will solve that

HTML fragment

<div class="input-group">
  <select class="form-control">
    <option value="ist">istanbul</option>
    <option value="ank">ankara</option>
    <option value="izm">izmir</option>
    <option value="adn">adana</option>
  </select>
  <span class="input-group-btn" style="width:0px;"></span>   <!--  added it here  -->
  <input type="text" class="form-control">
  <span class="input-group-btn">
    <button class="btn btn-default" type="button">Go!</button>
  </span>
</div>

Stack snippet

<!DOCTYPE html>
<html lang="en">
   <head>
      <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 -->
      <title>Bootstrap Tab</title>
      <!-- Bootstrap -->
      <!-- Latest compiled and minified CSS -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
      <!-- Optional theme -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" 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.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
      <![endif]-->
      <style type="text/css">
         .panel.with-nav-tabs .panel-heading{
         padding: 5px 5px 0 5px;
         }
         .panel.with-nav-tabs .nav-tabs{
         border-bottom: none;
         }
         .panel.with-nav-tabs .nav-justified{
         margin-bottom: -1px;
         }
         /********************************************************************/
         /*** PANEL DEFAULT ***/
         .with-nav-tabs.panel-default .nav-tabs > li > a,
         .with-nav-tabs.panel-default .nav-tabs > li > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li > a:focus {
         color: #777;
         }
         .with-nav-tabs.panel-default .nav-tabs > .open > a,
         .with-nav-tabs.panel-default .nav-tabs > .open > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > .open > a:focus,
         .with-nav-tabs.panel-default .nav-tabs > li > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li > a:focus {
         color: #777;
         background-color: #ddd;
         border-color: transparent;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.active > a,
         .with-nav-tabs.panel-default .nav-tabs > li.active > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li.active > a:focus {
         color: #555;
         background-color: #fff;
         border-color: #ddd;
         border-bottom-color: transparent;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu {
         background-color: #f5f5f5;
         border-color: #ddd;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a {
         color: #777;   
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > li > a:focus {
         background-color: #ddd;
         }
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a,
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a:hover,
         .with-nav-tabs.panel-default .nav-tabs > li.dropdown .dropdown-menu > .active > a:focus {
         color: #fff;
         background-color: #555;
         }
      </style>
   </head>
   <body>
      <div class="col-md-6 col-md-offset-3">
         <div class="panel with-nav-tabs panel-default">
            <div class="panel-heading">
               <ul class="nav nav-tabs">
                  <li class="active"><a href="#tab1default" data-toggle="tab">Arama 1</a></li>
                  <li><a href="#tab2default" data-toggle="tab">Arama 2</a></li>
               </ul>
            </div>
            <div class="panel-body">
               <div class="tab-content">
                  <div class="tab-pane fade in active" id="tab1default">
                     <div class="input-group">
                        <select class="form-control">
                           <option value="ist">istanbul</option>
                           <option value="ank">ankara</option>
                           <option value="izm">izmir</option>
                           <option value="adn">adana</option>
                        </select>
                        <span class="input-group-btn" style="width:0px;"></span>
                        <input type="text" class="form-control">
                        <span class="input-group-btn">
                        <button class="btn btn-default" type="button">Go!</button>
                        </span>
                     </div>
                     <!-- /input-group -->
                  </div>
                  <div class="tab-pane fade" id="tab2default">
                     <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search for...">
                        <span class="input-group-btn">
                        <button class="btn btn-default" type="button">Go!</button>
                        </span>
                     </div>
                     <!-- /input-group -->
                  </div>
               </div>
            </div>
         </div>
      </div>
      <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
   </body>
</html>

Upvotes: 1

Dilshan Fernando
Dilshan Fernando

Reputation: 1

Since you have bootstrap already, you can change the 1st tab as follows. col-xs-5 col-xs-5 col-xs-2 , adds up to 12 which is how bootstrap sizes a page.

       <div class="tab-pane fade in active" id="tab1default">
          <div class="row" >

              <div class="col-xs-5">
              <select class="form-control">
                       <option value="ist">istanbul</option>
                       <option value="ank">ankara</option>
                       <option value="izm">izmir</option>
                       <option value="adn">adana</option>
                    </select>
              </div>
               <div class="col-xs-5">
               <input type="text" class="form-control">
               </div>
                <div class="col-xs-2">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button">Go!     </button>
                    </span>
               </div>

        </div>
     </div>

Upvotes: 0

Gershon Papi
Gershon Papi

Reputation: 5106

Two options:

  1. Use bootstrap grid system to align the fields in a single row, hold all the form in a single .row with each field with a class of .col-**-**, to be the size of your choice. You can read more about bootstrap's grid here.
  2. enclose the first tab with a form tag and give it bootstrap's .form-inline class. You can read more about it here.

Upvotes: 0

Related Questions