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 });
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" ×
To change the color via:
Put these styles in your stylesheet after the bootstrap styles:
.modal-backdrop { background-color: red; }
Changes the bootstrap-variables to:
@modal-backdrop-bg: red;
Source
Changes the bootstrap-variables to:
$modal-backdrop-bg: red;
Source
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With