I am using bootstrap modal. When modal is open background content opacity is not changed by default. I tried changing in js using
function showModal() {
doc
The problem with overriding using !important
is that you will loose the fade in effect.
So the actual best trick to change the modal-backdrop opacity without breaking the fadeIn effect and without having to use the shameless !important
is to use this :
.modal-backdrop{
opacity:0; transition:opacity .2s;
}
.modal-backdrop.in{
opacity:.7;
}
@sass
.modal-backdrop{
opacity:0; transition:opacity .2s;
&.in{opacity:.7;}
}
Simple and clean.
you could utilize bootstrap events:: as
//when modal opens
$('#yourModal').on('shown.bs.modal', function (e) {
$("#pageContent").css({ opacity: 0.5 });
})
//when modal closes
$('#yourModal').on('hidden.bs.modal', function (e) {
$("#pageContent").css({ opacity: 1 });
})
Just setting height to 100% won't be the solution if you have a background page whose height extends beyond browser height.
Adding to Bhargavi's answer, this is the solution when you have scrollable page in the background.
.modal-backdrop.in
{
opacity:0.5 !important;
position:fixed;// This makes it cover the entire scrollable page, not just browser height
height:100%;
}
If you are using the less version to compile Bootstrap modify @modal-backdrop-opacity in your variables override file $modal-backdrop-opacity for scss.
What worked for me, I clear the opacity in .modal.backdrop.in
.modal-backdrop.in{
filter:alpha(opacity=50);
opacity:.5
}
change it to
.modal-backdrop.in{
}
I am assuming you want to set the opacity of the modal background...
Set the opacity via CSS
.modal-backdrop
{
opacity:0.5 !important;
}
!important
prevents the opacity from being overwritten - particularly from Bootstrap in this context.