Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the background color in a twitter bootstrap modal?

When creating a modal in twitter bootstrap, is there any way to change the background color? Remove the shading entirely?

NB: For removing shading, this doesn't work, because it also changes the click behavior. (I still want to be able to click outside the modal to close it.)

$("#myModal").modal({   backdrop: false }); 
like image 307
Abe Avatar asked May 14 '12 14:05

Abe


People also ask

What is backdrop in bootstrap modal?

The backdrop option specifies whether the modal should have a dark overlay (the background color of the current page) or not. Modal with Overlay (backdrop:true) Modal without Overlay (backdrop:false) Modal with backdrop:"static" ×


2 Answers

To change the color via:

CSS

Put these styles in your stylesheet after the bootstrap styles:

.modal-backdrop {    background-color: red; } 

Less

Changes the bootstrap-variables to:

@modal-backdrop-bg:           red; 

Source

Sass

Changes the bootstrap-variables to:

$modal-backdrop-bg:           red; 

Source

Bootstrap-Customizer

Change @modal-backdrop-bg to your desired color:

getbootstrap.com/customize/


You can also remove the backdrop via Javascript or by setting the color to transparent.

like image 110
HaNdTriX Avatar answered Sep 19 '22 11:09

HaNdTriX


If you want to change the background color of the backdrop for a specific modal, you can access the backdrop element in this way:

$('#myModal').data('bs.modal').$backdrop 

Then you can change any css property via .css jquery function. In particular, with background:

$('#myModal').data('bs.modal').$backdrop.css('background-color','orange') 

Note that $('#myModal') has to be initialized, otherwise $backdrop is going to be null. Same applies to bs.modal data element.

like image 29
muZk Avatar answered Sep 20 '22 11:09

muZk