Bouton sur toute la largeur avec bootstrap

Active 31 octobre 2017    /    Viewed 3349    /    Comments 0    /    Edit


Avec bootstrap on peut facilement créer un bouton

<button type="submit" class="btn btn-default" >Search</button>

si on veut que le bouton fasse toute la largeur du "block" dans lequel il est placé il suffit de rajouter, sous bootstrap v3 or 4, l'option "btn-block", comme ceci:

<button type="submit" class="btn btn-default btn-block" >Search</button>

Note 1: Pour centrer un bouton il faut ajouter "text-center" dans un bloc contenant le bouton.

Note 2: pour bootstrap v2, l'option était: input-block-level

Bouton sur toute la largeur avec bootstrap

Code pour obtenir l'image ci-dessus

<!DOCTYPE html>
<html lang="en">
<head>

  <title>Bootstrap Example</title>

  <meta charset="utf-8">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <style>
  body {
  padding-top: 50px;
  background-color:#FFFFF; 
  }
  </style>

</head>
<body>

<div class="container">

<div class="row">
<div class="col-md-4">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">Simple Button</h4>
        </div>
        <div class="panel-body">
            <button type="submit" class="btn btn-default" >Search</button>
        </div>
    </div>   
</div>
</div>

<div class="row">
<div class="col-md-4">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">Center Button</h4>
        </div>
        <div class="panel-body text-center">
            <button type="submit" class="btn btn-default" >Search</button>
        </div>
    </div>   
</div>
</div>

<div class="row">
<div class="col-md-4">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">Full-Width Button</h4>
        </div>
        <div class="panel-body">
            <button type="submit" class="btn btn-default btn-block" >Search</button>
        </div>
    </div>   
</div>
</div>

</div>

</body>
</html>

Références

Liens Site
Making button go full-width? stackoverflow
Buttons bootstrap.com
How to center buttons in Twitter Bootstrap 3? stackoverflow
How to align button to center using Bootstrap stackoverflow


Card image cap
profile-image
Daidalos

Hi, I am Ben.

I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!