Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering two buttons with Bootstrap

I'm trying to center two form buttons with Bootstrap but I can't get it to work!

here is my code:

<!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">
    <title>Form</title>

    <!-- Bootstrap -->
    <link href="static/fw/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/fw/css/bootstrap-theme.min.css" rel="stylesheet">

    <!-- Custom styles -->
    <link href="static/code/style.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js 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.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>


    <div class="container" role="main">

        <div  class="center-block">
            <button type="submit" class="btn btn-success">Save</button>
            <button type="submit" class="btn btn-danger">Cancel</button>
        </div>


    </div> <!-- /container -->

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="static/fw/js/bootstrap.min.js"></script>
    <script src="static/code/script.js"></script>
  </body>
</html>
like image 960
Jack Twain Avatar asked Dec 20 '22 10:12

Jack Twain


2 Answers

You need to add your row and col classes, also use text center

    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                <div  class="text-center">
                    <button type="submit" class="btn btn-success">Save</button>
                    <button type="submit" class="btn btn-danger">Cancel</button>
                </div>
            </div>
        </div>
    </div>
like image 81
Chico3001 Avatar answered Dec 22 '22 01:12

Chico3001


Add .text-center to the div containing the buttons.

http://jsbin.com/sosab/1/edit?html,output

like image 34
ragefuljoe Avatar answered Dec 22 '22 00:12

ragefuljoe