Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap buttons in one line

Buttons

Here is my code, and i dont know how to place the buttons side to side. (btw I'm new at coding)

<div class="second">
           <div class="col-md-12 text-center">
               <form>
            <button class="btn btn-primary btn-lg" type="submit" formaction="1klasse.html">1.klasse </button>
               </form>
           </div>
            <div class="col-md-8 text-center">
                <form>
                    <button class="btn btn-primary btn-lg" type="submit" formaction="1klasse.html">2.klasse </button>
                </form>
            </div>
        </div>
like image 813
Dogan Can Avatar asked May 30 '17 08:05

Dogan Can


People also ask

How do I make two buttons in one line in Bootstrap?

Use the . btn-group class in Bootstrap to group buttons on a single like.

How do I put Bootstrap buttons side by side?

You can use an out div with a class btn-group . This helps to align the buttons horizontally. Using col-md-6 for each button div can make the buttons missaligned with unwanted space in between.

How multiple buttons can be created at once by Bootstrap?

Instead of applying button sizing classes to every button in a group, just add . btn-group-* to each . btn-group , including each one when nesting multiple groups.


2 Answers

Since you are using bootstrap, there are a few things you need to know:

.col class will not work without putting the class within .container and .row classes. The other important thing is that the column numeric sizes add up to 12; right now yours add to 20. So your code should look more like this:

<div class="container">
  <div class="row">
    <div class="col-12 col-md-6">
       <form>
        <button class="btn btn-primary btn-lg" type="submit" formaction="1klasse.html">1.klasse </button>
       </form>
    </div>
    <div class="col-12 col-md-6">
      <form>
        <button class="btn btn-primary btn-lg" type="submit" formaction="1klasse.html">1.klasse </button>
       </form>
    </div>
  </div>
</div>

Here is a codepen to show it working

Refer to Bootstrap documentation on grids as well

like image 101
Adam H Avatar answered Oct 13 '22 13:10

Adam H


Just put the buttons inside the same form and div

<div class="second">
     <div class="col-md-12 text-center">
           <form>
                <button class="btn btn-primary btn-lg" type="submit" formaction="1klasse.html">1.klasse </button>
                <button class="btn btn-primary btn-lg" type="submit" formaction="1klasse.html">2.klasse </button>
            </form>
      </div>
</div>
like image 35
EstevaoLuis Avatar answered Oct 13 '22 15:10

EstevaoLuis