javascript - Prevent or remove full screen overlay from bootstrap modal - Stack Overflow

When opening a bootstrap modal, it contains a shadowdark backdrop. If you set this backdrop to false i

When opening a bootstrap modal, it contains a shadow/dark backdrop. If you set this backdrop to false it removes the shadow, but the large area behind the modal still remains, preventing anything in the background from being clicked.

Is there a way to limit the size of a modal to the size of the actual .modal-content area?

Here is a fiddle demoing the issue: /

Right click and Inspect the background outside of the modal and you will still it still belongs to the modal object, preventing you from clicking the background behind it.

When opening a bootstrap modal, it contains a shadow/dark backdrop. If you set this backdrop to false it removes the shadow, but the large area behind the modal still remains, preventing anything in the background from being clicked.

Is there a way to limit the size of a modal to the size of the actual .modal-content area?

Here is a fiddle demoing the issue: https://jsfiddle/s75L8z1v/

Right click and Inspect the background outside of the modal and you will still it still belongs to the modal object, preventing you from clicking the background behind it.

Share Improve this question edited Mar 31, 2017 at 20:11 SISYN asked Mar 31, 2017 at 19:24 SISYNSISYN 2,2695 gold badges26 silver badges46 bronze badges 2
  • you can use CSS to do display: none on the backdrop. – eric Commented Mar 31, 2017 at 19:42
  • Does not work, as this backdrop is contained within the parent modal, please check fiddle provided. – SISYN Commented Mar 31, 2017 at 20:11
Add a ment  | 

2 Answers 2

Reset to default 5

You seem to want popover behavior with modal styling.

I believe it's easier to provide modal styling to a popover than to strip the behavior from a modal and I can't guarantee it's going to work on all devices properly. At first glance, seems like a no-no from user-experience, expectations and, ultimately, satisfaction point of view.

Modals are supposed to focus attention and be dismissed. If you don't need that, you should probably center a popover.

Nonetheless, here is what should be done:

  1. Re-enable scroll on <body> when modal is open.
  2. disable pointer-events on .modal-content (so elements beneath can catch them).
  3. (re-)enable pointer-events on .modal-content
  4. add display:none to .modal-backdrop. Note this can also be achieved using backdrop: false in modal options.

Or, translated in CSS:

body.modal-open { overflow: auto; }
.modal.in { pointer-events: none; }
.modal-content { pointer-events:all; }
.modal-backdrop { display: none; }

Demo:

body.modal-open {
  overflow: auto;
}
.modal.in {
  pointer-events: none;
}
.modal-content {
  pointer-events:all;
}
.modal-backdrop {
  display: none;
}

/* 
 * you don't need the CSS below, it's only for SO,
 */

.text-center > .btn-primary {
 display: inline-block;
 margin: 7rem auto;
}
<link href="https://maxcdn.bootstrapcdn./bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn./bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- Button trigger modal -->
<div class="text-center">
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<div class="container">

<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a plete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?

<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be weled and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.

<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a plete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?

<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be weled and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.

<p>[32] But I must explain to you how all this mistaken idea of denouncing of a pleasure and praising pain was born and I will give you a plete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?

<p>[33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be weled and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
</div>

Override the modal's CSS with your own:

.modal {
  right: initial;
  bottom:initial;
  width: 200px;
}

See the fiddle here

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745673280a4639535.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信