打开bootstrap模式弹出窗口时启用后台

use*_*761 7 css twitter-bootstrap bootstrap-modal

我在我的项目中使用了bootstrap的模式弹出窗口,并希望得到以下内容:

  1. 当打开模态弹出窗口并单击后台弹出窗口时,不应该关闭.
  2. 当打开模态弹出背景时不应该模糊.意思是打开模态弹出背景不应该影响任何方式.
  3. 打开模态弹出窗口后,用户也可以在后台弹出窗口不应该关闭的情况下工作.

She*_*ary 13

1)当打开模型弹出窗口并单击后台弹出窗口时,不应该关闭.

data-keyboard="false" data-backdrop="static"在模态定义中包含数据属性:

<div class="modal fade" id="myModal" role="dialog" data-keyboard="false" data-backdrop="static">
    // Modal HTML Markup
</div>
Run Code Online (Sandbox Code Playgroud)

2)当打开模型弹出背景时不应模糊.意思是打开模型弹出背景不应该影响任何方式.

.modal-backdrop属性值设置为display:none;

.modal-backdrop {
    display:none;
}
Run Code Online (Sandbox Code Playgroud)

3)打开模型弹出后,用户也可以在弹出窗口不应该关闭的后台工作.

添加值 .modal-open .modal

.modal-open .modal {
    width: 300px;
    margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)

SideNote:您可能需要根据媒体查询的屏幕大小调整模态的宽度.

免责声明:这个答案只是为了演示如何实现所有3个目标如果你有一个以上的bootstrap模态,上面的更改将影响所有模态,强烈建议使用自定义选择器.

.modal-backdrop {
  display: none !important;
}
.modal-open .modal {
    width: 300px;
    margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button>
<br> This is a text and can be selected for copying
<br> This is a text and can be selected for copying
<br> This is a text and can be selected for copying
<br> This is a text and can be selected for copying
<br>

<div id="myModal" class="modal fade" role="dialog" data-backdrop="static">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

工作小提琴示例