Bootstrap Modals

The bootstrap modal plugin is a dialog box / popup window that is displayed on top of the current page.

Bootstrap Modal Example

<!DOCTYPE html>  

<html lang="en">  

<head>  

  <title>Bootstrap Example</title>  

  <meta charset="utf-8">  

  <meta name="viewport" content="width=device-width, initial-scale=1">  

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

    

</head>  

<body>  

  

<div class="container">  

  <h2>Modal Example</h2>  

  <!-- Trigger the modal with a button -->  

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>  

  

  <!-- Modal -->  

  <div class="modal fade" id="myModal" role="dialog">  

    <div class="modal-dialog">  

      

      <!-- Modal content-->  

      <div class="modal-content">  

        <div class="modal-header">  

          <button type="button" class="close" data-dismiss="modal">×</button>  

          <h4 class="modal-title">Modal Header</h4>  

        </div>  

        <div class="modal-body">  

          <p>Write your text in the modal.</p>  

        </div>  

        <div class="modal-footer">  

          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  

        </div>  

      </div>  

        

    </div>  

  </div>  

    

</div>  

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>  

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  

</body>  

</html> 

Bootstrap Modal Size

You can change the size of the modal by adding the .modal-sm class for small modals or .modal-lg class for large modals.

The size class is added to the <div> element with class .modal-dialog.

Small Modal:

See this example:

<!DOCTYPE html>  

<html lang="en">  

<head>  

  <title>Bootstrap Example</title>  

  <meta charset="utf-8">  

  <meta name="viewport" content="width=device-width, initial-scale=1">  

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

    

</head>  

<body>  

  

<div class="container">  

  <h2>Small Modal</h2>  

  <!-- Trigger the modal with a button -->  

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Small Modal</button>  

  

  <!-- Modal -->  

  <div class="modal fade" id="myModal" role="dialog">  

    <div class="modal-dialog modal-sm">  

      <div class="modal-content">  

        <div class="modal-header">  

          <button type="button" class="close" data-dismiss="modal">×</button>  

          <h4 class="modal-title">Modal Header</h4>  

        </div>  

        <div class="modal-body">  

          <p>This is a small modal.</p>  

        </div>  

        <div class="modal-footer">  

          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  

        </div>  

      </div>  

    </div>  

  </div>  

</div>  

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>  

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  

</body>  

</html>

Bootstrap Large Modal

See this example:

<!DOCTYPE html>  

<html lang="en">  

<head>  

  <title>Bootstrap Example</title>  

  <meta charset="utf-8">  

  <meta name="viewport" content="width=device-width, initial-scale=1">  

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

    

</head>  

<body>  

  

<div class="container">  

  <h2>Large Modal</h2>  

  <!-- Trigger the modal with a button -->  

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Large Modal</button>  

  

  <!-- Modal -->  

  <div class="modal fade" id="myModal" role="dialog">  

    <div class="modal-dialog modal-lg">  

      <div class="modal-content">  

        <div class="modal-header">  

          <button type="button" class="close" data-dismiss="modal">×</button>  

          <h4 class="modal-title">Modal Header</h4>  

        </div>  

        <div class="modal-body">  

          <p>This is a large modal.</p>  

        </div>  

        <div class="modal-footer">  

          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  

        </div>  

      </div>  

    </div>  

  </div>  

</div>  

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>  

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  

</body>  

</html>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *