Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap form inline not working

I am trying to add this simple search form while applying form inline class so that controls appear next to each other, but I get the controls displayed above each other and the search bottom in white and looking strange, so can someone please tell me what I am missing here?

<div class="container">
    <div class="row">
          <div class="col-md-8">
                <form class="form-inline" action="#" method="post">
                    Search<input type="text" id="search" name="search" class="input-small" placeholder="Search...">
                    <select id="searchon" name="searchon">
                        <option value="0">First Name</option>
                        <option value="1">Last Name</option>
                    </select>
                    <button type="submit" class="btn">Search</button>
                </form>       
          </div>      
    </div>
</div>
like image 680
MChan Avatar asked Jan 09 '14 10:01

MChan


People also ask

What is form-inline in bootstrap 5?

Inline formsUse the .row-cols-* classes to create responsive horizontal layouts. By adding gutter modifier classes, we'll have gutters in horizontal and vertical directions. On narrow mobile viewports, the .col-12 helps stack the form controls and more.

What can I use instead of form Group in bootstrap 5?

form-group can be replaced with mb-3 , since it previously applied the property margin-bottom: 1rem which the mb-3 class will do by default as well. Form specific layout classes are dropped (source: Migration guide). form-row can be replaced with row in most instances.

How to make form using bootstrap?

Inline Form To create a form where all of the elements are inline, left aligned and labels are alongside, add the class . form-inline to the <form> tag. By default inputs, selects, and textareas have 100% width in Bootstrap. You need to set a width on the form controls when using inline form.

Why we use form group in bootstrap?

The .form-group class is the easiest way to add some structure to forms. It provides a flexible class that encourages proper grouping of labels, controls, optional help text, and form validation messaging. By default it only applies margin-bottom , but it picks up additional styles in .form-inline as needed.


2 Answers

I had similar issue with form-inline. For me input-group within form-inline worked to keep following input and button in a row next to each other instead of one on top of the other.

<form class="form-inline">
  <div class="input-group">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </div>
</form>
like image 93
Nafeez Quraishi Avatar answered Oct 28 '22 01:10

Nafeez Quraishi


I had a similar issue with a code snippet from bootstrap. I found that the 2 classes 'control-group' and 'controls' broke the inline. removing the 2 classes fixed it for me.

<div class="control-group">
            <label class="control-label" for="Name">Name</label>
            <div class="controls">
                <input type="text" id="Name" placeholder="Name">
            </div>
        </div>

to:

            <label class="control-label" for="Name">Name</label>

                <input type="text" id="Name" placeholder="Name">
like image 37
learnerplates Avatar answered Oct 28 '22 00:10

learnerplates