I have a menu with multiple modals. When I open one over another it turns backgrount into black, which is ugly. I understand that I need change filter: alpha(opacity=80);
in .modal-backdrop.fade.in
in bootstrap.css. But I need to change it not for all modals, only for some of them. Here's the html code for first modal
<div class="modal hide" id="mbusModal"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h3>MBUS</h3> </div> <div class="modal-body"> <form class="form-horizontal"> <form class="well form-inline"> <input type="button" class="btn" onclick="$('#dinMbusModal').modal('show'); $('#tabsMbusDin a:last').tab('show');" value="din"> </form> </div> <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Закрыть</a> <a href="#" class="btn btn-primary" onclick="addPort('mbus',$('#mbusDev').val(),$('#mbusSpeed').val()); $('#mbusModal').modal('hide')">Применить</a> </div>
This modal needs to change his backdrop:
<div class="modal hide" id="dinMbusModal" style="width: 500px; margin: -250px 0 0 -250px;"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h3>DIN</h3> </div> <div class="modal-body"> </div> <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Закрыть</a> <a href="#" class="btn btn-primary" onclick="addPort('din_mbus',,); $('#dinMbusModal').modal('hide')">Применить</a> </div> </div>
remove(); $('. modal-backdrop'). remove(); $('body'). removeClass( "modal-open" );
The data-backdrop attribute specifies whether the modal should have a dark overlay (the background color of the current page) or not. Modal with Overlay (true) Modal without Overlay (false) Modal with static backdrop. ×
The .fade class adds a transition effect which fades the modal in and out. Remove this class if you do not want this effect. The attribute role="dialog" improves accessibility for people using screen readers.
Little bit complicated by the fact that the backdrop is generated by the Modal plugin on the fly. One possible way of doing it is adding a class to the body when you get a show event, then remove it on the hidden.
Something like:
.modal-color-red .modal-backdrop { background-color: #f00; } .modal-color-green .modal-backdrop { background-color: #0f0; } .modal-color-blue .modal-backdrop { background-color: #00f; }
$('.modal[data-color]').on('show hidden', function () { $('body').toggleClass('modal-color-'+ $(this).data('color')); });
<div class="modal hide fade" id="redModal" data-color="red">...</div> <div class="modal hide fade" id="greenModal" data-color="green">...</div> <div class="modal hide fade" id="blueModal" data-color="blue">...</div>
ONLY CSS / HTML
JSFiddle: http://jsfiddle.net/szoys6d7/
HTML
<div class="modal hide fade modal2">...</div>
CSS
.modal2.fade.in ~ .modal-backdrop.fade.in { background-color: #f00; }
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