Crear un modal con Boostrap

Tiempo de lectura: 2 minutos

Reading time: 2 minutes

To create a modal with Bootstrap and HTML, follow these steps:

  • Include the Bootstrap stylesheet in your HTML file. You can do this by downloading the CSS file from the Bootstrap website or including a link to an online version in your HTML file.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

Add the HTML code for your modal anywhere within the body of your page. The HTML code should include a container for the modal content, a button or link to open the modal, and a button to close it.

<!-- Button to open the modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
  Open modal
</button>

<!-- Modal container -->
<div class="modal" tabindex="-1" role="dialog" id="myModal">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal content</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Include the Bootstrap JavaScript library in your HTML file to enable modal functionality. You can do this by downloading the JavaScript file from the Bootstrap website or including a link to an online version in your HTML file.

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

Optionally, you can customize the appearance of the modal using CSS. Bootstrap provides predefined classes that allow you to modify the size, position, and other aspects of the modal.

Note: It’s important to remember that in order to use Bootstrap, you need an internet connection as it relies on external files. If you want to use Bootstrap offline, you can download the CSS and JavaScript files and host them on your server or local project.

To create a modal with Bootstrap and HTML, follow these steps:

  • Include the Bootstrap stylesheet in your HTML file. You can do this by downloading the CSS file from the Bootstrap website or including a link to an online version in your HTML file.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

Add the HTML code for your modal anywhere within the body of your page. The HTML code should include a container for the modal content, a button or link to open the modal, and a button to close it.

<!-- Button to open the modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
  Open modal
</button>

<!-- Modal container -->
<div class="modal" tabindex="-1" role="dialog" id="myModal">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal content</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Include the Bootstrap JavaScript library in your HTML file to enable modal functionality. You can do this by downloading the JavaScript file from the Bootstrap website or including a link to an online version in your HTML file.

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

Optionally, you can customize the appearance of the modal using CSS. Bootstrap provides predefined classes that allow you to modify the size, position, and other aspects of the modal.

Note: It’s important to remember that in order to use Bootstrap, you need an internet connection as it relies on external files. If you want to use Bootstrap offline, you can download the CSS and JavaScript files and host them on your server or local project.

Leave a Comment