如何修复bootstrap模式中的一个元素相对于bootstrap模式

时间:2015-08-17 01:47:51

标签: jquery html css twitter-bootstrap css-position

我想在bootstrap模式中修复一个元素,但是position: fixed但是在滚动时它会随着模态一起移动。即使在滚动模态之后,我也希望它能够固定在它的位置。

这是JSFiddle。在这里,您将看到Patate文本具有position: fixed css属性,但如果模态较大,则随之移动。如何将此文本固定到其位置,以便即使模式滚动也能保持其位置。

我没有运气。请帮忙。感谢。

1 个答案:

答案 0 :(得分:5)

这可能会有所帮助。使用模态中的网格将固定div与其余内容分开。

$('.launch-scroll').on('click', function(e) {
  $('#modal-scroll').modal({
    show: true
  });
});
.modal {
    overflow: hidden;
}
.modal .modal-body {
    height: 500px;
    overflow: auto;
}
.modal .modal-fixed {
    position: fixed;
    background-color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="page-container">
  <div class="container">
    <br />
    <button type="button" class="btn launch-scroll">Launch Confirm</button>
  </div>
</div>
<div class="modal fade" id="modal-scroll">
  <div class="modal-dialog">
    <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">Modal title</h4>

      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-xs-2">
            <div class="modal-fixed">Patate</div>
          </div>
          <div class="col-xs-10">
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
            <p>One fine body&hellip;</p>
          </div>
        </div>
      </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>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->