Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why No Line Break After Input In Bootstrap

Here is the code that I'm using for a simple form. I pretty much copied the entire form from the example on Bootstrap's website, and removed all controls except a text input and the submit button.

<form>
    <fieldset>
        <legend>About You</legend>
        <input class="input-medium" type="text" placeholder="First Name">
        <button type="submit" class="btn">Get Started</button>
    </fieldset>
</form>

For some reason, the submit button doesn't drop to a new line when it comes right after an input.

Demonstration of it not working.

You'll see, if I just add the checkbox w/ label back from the example, the submit button drops to a new line as expected.

<form>
    <fieldset>
        <legend>About You</legend>
        <input class="input-medium" type="text" placeholder="First Name">
        <label class="checkbox">
            <input type="checkbox"> Check me out
        </label>
        <button type="submit" class="btn">Get Started</button>
    </fieldset>
</form>

Working when button does not come after text input.

What am I doing wrong? I'm using the latest bootstrap CSS and JS (2.3.2), loaded from BootstrapCDN.com.

like image 972
Sajan Parikh Avatar asked Jun 23 '13 06:06

Sajan Parikh


People also ask

How do you put a line break in input?

To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' .

How do you not break a line?

There are several ways to prevent line breaks in content. Using &nbsp; is one way, and works fine between words, but using it between an empty element and some text does not have a well-defined effect. The same would apply to the more logical and more accessible approach where you use an image for an icon.

What is 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.


1 Answers

Both <input> and <button> have display: inline-block.
<label> has display: block and forces button to be rendered on the next line.


The workaround for displaying button in the next line is simply wrap it in an element with display: block, i.e. in a <div> element.
Look at this FIDDLE DEMO

like image 144
Artyom Neustroev Avatar answered Oct 23 '22 04:10

Artyom Neustroev