Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to customize style of bootstrap $modal

In my application I am using bootstrap $modal popup two different times. content of both pop-ups is different hence size of both pop-up must be also different. I tried to style $modal using

.modal {
    display: block;
    position: absolute;
    left: 60%;
    height: 88%;
    width: 28%;
    overflow-y:auto;
    overflow-x:auto;
    border-radius: 0px;
}

but as expected it is changing style of both of my pop-ups. Is there any way to apply different class to each popup?

Thanks in advance.

like image 545
Aditya Ponkshe Avatar asked Dec 31 '13 08:12

Aditya Ponkshe


People also ask

How to style modal in Bootstrap?

Use the.modal-body class in Bootstrap to style the modal. You can try to run the following code to style modal −/p>

What is the difference between modal-body and modal class?

The .close class styles the close button, and the .modal-title class styles the header with a proper line-height. The .modal-body class is used to define the style for the body of the modal. Add any HTML markup here; paragraphs, images, videos, etc. The .modal-footer class is used to define the style for the footer of the modal.

How do I customize my bootstrap site?

If you want to customize your Bootstrap site, you can leave the source code as is and simply add custom code in an external stylesheet. The code in this external stylesheet will override the existing styles — as long as it’s set up properly. This set-up process differs slightly, depending on how you load Bootstrap on your site.

How do I create a modal with HTML markup?

The.modal-body class is used to define the style for the body of the modal. Add any HTML markup here; paragraphs, images, videos, etc. The.modal-footer class is used to define the style for the footer of the modal. Note that this area is right aligned by default.


2 Answers

If you have access to HTML, Then you can add an extra class to the modal like <div class="modal custom"> then you can style it like .modal.custom. Full example below

Working Demo

HTML

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal2">
  Variable Modal
</button>

<!-- Modal -->
<div class="modal custom fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
   ....

CSS

.modal.custom .modal-dialog {
    width:50%;
    margin:0 auto;
    /*add what you want here*/
}

Let me know if you have further issues in the comments.

like image 186
Surjith S M Avatar answered Oct 21 '22 03:10

Surjith S M


Update 2017 - Bootstrap 4

The structure of the modal has changed since Bootstrap 3, so now different CSS is required to customize the position, size or modal styles. To change the modal width, set the max-width on the modal-dialog, for exmaple:

.modal.custom .modal-dialog {
    max-width: 50%;
}

Custom modal demo

like image 31
Zim Avatar answered Oct 21 '22 02:10

Zim