Align Submit button along with Bootstrap input

Asked

Viewed 17,770 times

5

I have the following code that uses bootstrap 3 consisting of an input and a Submit button. Currently the button is below the input, but I want it to be aligned laterally with the input. I have seen some questions here but the answers did not solve the problem.

Code:

<body>
    <nav class="navbar navbar-default" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
                    <span class="sr-only">Toggle navigation</span> 
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button> 
                <a class="navbar-brand" href="#">Meu Site</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">News</a></li>
                    <li><a href="#">Login</a></li>
                    <li><a href="#">Create Account</a></li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container -->
    </nav>

    <div class="container">
        <div class="row">
            <form class="span7 text-center col-md-4 col-md-offset-3" style="float: none; margin-left: auto;margin-right: auto;" role="search">
                    <div class="form-group">
                        <label class="radio-inline"><input type="radio" name="optradio">Opt1</label>
                        <label class="radio-inline"><input type="radio" name="optradio" checked="">Opt2</label>
                        <label class="radio-inline"><input type="radio" name="optradio">Opt3</label>
                        <input class="form-control" type="text" placeholder="Search" />
                    </div>
                    <button class="btn btn-default" type="submit">Search</button>
            </form>
        </div>
    </div>
</body>

The site like this Imagem de como esta

The site as I want (search button aligned to the right and radio Buttons centralized between the input and the button)

inserir a descrição da imagem aqui

  • Have you tried putting the button inside the div form?

  • Yes, the button is "Pasted below the input"

  • Is that good? http://jsfiddle.net/a6Lt5Lgx/show/

  • Yeah, like you did to get like this?

  • I posted as an answer.

1 answer

6


Create a div with the class input-group and add input and button inside, use class input-group-btn in the div where the button will be.

<div class="input-group">
    <input class="form-control" type="text" placeholder="Search" />
    <div class="input-group-btn">
        <button class="btn btn-default" type="submit">Search</button>
    </div>
</div>

Example: http://jsfiddle.net/a6Lt5Lgx/

  • how could increase the size of the input and button?

  • In the documentation you have the classes you can use, for button and input. Just add the class.

  • You would know how to center vertically and horizontally?

  • Ricardo, I’ve never worked with bootstrap, so I can’t help much, what little I know is researching! :/

  • Me neither, today is my third day working with bootstrap.

  • Good luck friend! I believe that quickly you will manage to master. =)

  • @Ricardo you would like to centralize what ? Bootstap owns the class text-center to center text, just put in the "parent" the text will be centered.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.