Click here to Skip to main content
15,891,633 members
Articles / Web Development / HTML
Tip/Trick

Bootstrap Popups

Rate me:
Please Sign up or sign in to vote.
4.88/5 (13 votes)
2 Oct 2014CPOL1 min read 67.4K   5   23   3
This tip presents an example of popups in responsive using bootstrap

Introduction

This tip presents an example of popups in bootstrap. In many kind of situations, we require to display data in popups so, now I am going to show in this tip how popups work in bootstrap with responsive mode.

Here, I show an example that is very simple and easy. Here is my main intention is to display popup.

Background

Bootstrap

Bootstrap is the most popular for HTML, CSS and JS framework for developing responsive applications.

Responsive

Responsive means the single application will target any device like mobile, tablet, small PC and large PC.

Popup

The popup means a dialog will appear with rich UI.

Using the Code

Here is the code to display Popup in responsive mode.

The JQuery is the top of all the .js libraries.

First, we need to include the required libraries.

C++
//
// These are the required libraries u must include
//

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">   
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" 
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

After including all required libraries, put your HTML popup code.

Here my requirement is to display two links, one is PostComment and Login.

When you click the link, popup will appear with required fields.

For that purpose, we just put the initial display links code:

C++
//
// These code for display links
//
<div class="container">
<div class="row header" style="text-align:center;color:green">
<h3>Bootstrap popups (Responsive)</h3>
</div>
<div class="row header" style="text-align:center;margin-top:40px;">
 <a href="#" data-toggle="modal" 
 data-target="#PostCommentsModal">Post Comments</a></br></br>
  <a href="#" data-toggle="modal" data-target="#LoginModal">Login</a>
</div>

After displaying link, we will map popups to that link. The popup code is below:

C++
//
//This is the code for postcomment popup
//


<div class="modal fade" id="PostCommentsModal" tabindex="-1" 
role="dialog" aria-labelledby="helpModalLabel"     aria-hidden="true">
            <div class="modal-dialog">      
         <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" 
                        data-dismiss="modal">
                            <span aria-hidden="true">&times;
                            </span><span class="sr-only">
Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">
                            Post Comment</h4>
                    </div>
   <div class="modal-body">
                       <div class="input-group">
            <span class="input-group-addon">@</span>
            <input type="text" class="form-control" 
            placeholder="Your Name" />
        </div>
        <p>
        </p>
        <div class="input-group">
            <span class="input-group-addon">@</span>
            <input type="text" class="form-control" 
            placeholder="Your Email" />
        </div>
        <p>
        </p>
        <div class="input-group">
            <span class="input-group-addon">@</span>
            <textarea rows="4" cols="50" 
            class="form-control" placeholder="Your Message">
</textarea>
        </div>
        <p>
        </p>
        <button type="button" class="btn-primary">
            Send</button>
                    </div>
                    <div class="modal-footer">
                        <button type="button" 
                        class="btn btn-default" data-dismiss="modal">
                            Close</button>
                    </div>
                </div>
            </div>
        </div>

//
//This is the code for the Login popup
//
<div class="modal fade" id="LoginModal" tabindex="-1" 
role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">
                            <span aria-hidden="true">&times;
                            </span><span class="sr-only">
                                     Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">
                            Login</h4>
                    </div>
                    <div class="modal-body">
                       <div class="input-group">
            <span class="input-group-addon">@</span>
            <input type="text" class="form-control" placeholder="Email" />
        </div>
        <p>
        </p>
        <div class="input-group">
            <span class="input-group-addon">@</span>
            <input type="text" class="form-control" placeholder="Password" />
        </div>
        <p>
        </p>  
    <button type="button" class="btn-primary">
            SignIn</button>
<button type="button" class="btn-primary">
            SignUp</button>
                    </div>
                    <div class="modal-footer">
                        <button type="button" 
                        class="btn btn-default" data-dismiss="modal">
                            Close</button>
                    </div>
                </div
            </div>
        </div>

That's it. Now popups are working in responsive mode.

The final output in initial is like this:

Image 1

The post comment screen is like this in any mode (mobile, tablet, desktop...):

Image 2

The Login screen is like this in any mode (mobile, tablet, desktop...):

Image 3

Points of Interest

I worked on many popup controls but bootstrap popups are very good rich UI and much simpler.

History

  • 2014-10-02

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
QuestionNice and to the point Pin
Gaston Verelst21-Dec-14 9:10
Gaston Verelst21-Dec-14 9:10 
QuestionYou did an excellent job Pin
Santhosh Babu Mahimairaj2-Oct-14 22:05
professionalSanthosh Babu Mahimairaj2-Oct-14 22:05 
GeneralMy Vote 5 Pin
Shemeemsha (ഷെമീംഷ)2-Oct-14 19:43
Shemeemsha (ഷെമീംഷ)2-Oct-14 19:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.