Bootstrap Modal Dialogs

Bootstrap Modal Dialogs
Nikhil
Published on 2021-07-24 13:42:59

HTML etiquette

A Bootstrap modal dialogue is a component that creates a floating modal dialogue window over page-level content. The following is an example of how to use a Bootstrap modal dialogue in HTML:

Example:

<div class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body">
                <p>One fine body&hellip;</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

 

Basic Javascript usage and initialization

The jQuery function $('#myModal') can be used to create modal dialogue components. $('#myModal') is a top-level reference to the particular modal dialogue, and options is a Javascript object setting the modal dialog's default properties.

Multiple properties can be defined in the options object, which determines how the modal dialogue works. These characteristics are defined as follows:

  • A user can specify whether or not they want a grey background overlay to show behind the modal dialogue using the backdrop attribute. The string "static" and boolean values are both recognized.
  • When a user clicks on the background overlay, the modal dialogue will not be dismissed if "static" is set.
  • When the escape key is struck on the keyboard, the keyboard property allows the user to specify whether or not they want the modal dialogue to close.
  • When the modal is initialized, the show property allows the user to specify whether or not they want the modal dialogue to appear.

Here is an example of the basic Javascript usage:

$('#carModal').modal({ backdrop: false, keyboard: true, show: false });

As with other Bootstrap components, the modal's options can also be specified in HTML via data attributes.

 

ATutorialHub Related Guide

Comments (8)

Leave a Comment

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

User Comments

html tutorial comments

panduranga gupta

2021-07-05 07:03:13

good website for learning and help me a lot

html tutorial comments

raju

2021-09-25 14:58:47

The awsome website i am looking like for a long time, good work atutorialhub team keep doing

html tutorial comments

Shivani

2021-09-01 15:03:56

Learning a lot from the courses present on atutorialhub. The courses are very well explained. Great experience

html tutorial comments

Harshitha

2021-09-10 15:05:45

It is very helpful to students and easy to learn the concepts

html tutorial comments

Sowmya

2021-09-14 15:06:41

Great job Tutorials are easy to understand Please make use of it

html tutorial comments

Zain Khan

2021-09-18 15:07:23

Great content and customized courses.

html tutorial comments

Rudrakshi Bhatt

2021-09-09 15:08:10

Well structured coursed and explained really well!

html tutorial comments

Pavana Somashekar

2021-09-11 15:09:08

Good platform for beginners and learn a lot on this website