在Bootstrap模态中调整表内容的大小

时间:2018-07-18 15:01:54

标签: javascript html css twitter-bootstrap

我使用Bootstrap做了一个简单的模态,允许用户查看表内容。但是,我在尝试将表内容保留在模式中时遇到问题。

当我减小网站/模式的大小时,表内容将超出模式。有什么方法可以使用户滚动,以便他们可以查看其中的所有表内容?

这是我的JSFiddle代码:

<button type="button" class="btn btn-default" data-toggle="modal" data-target="#complex">Button</button>
<div class="modal fade" id="complex" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Test</h4>
      </div>
      <div class="modal-body">
        <table id="example" class="table">
          <thead>
            <tr>
              <th>First Name</th>
              <th>Last Name</th>
              <th>ID Number</th>
              <th>Proband</th>
              <th>Gender</th>
              <th>Birth Date</th>
              <th>Life Status</th>
              <th>Phenotype</th>
              <th>Genotype</th>
              <th>&nbsp;</th>
            </tr>
          </thead>
        </table>
      </div>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

2 个答案:

答案 0 :(得分:0)

如果要在模式容器上滚动,则只能使用CSS。 在这里寻找小提琴:http://jsfiddle.net/oq0xLmz2/

.modal-body {
    overflow : auto;
}

答案 1 :(得分:-1)

<button type="button" class="btn btn-default" data-toggle="modal" data-target="#complex">Button</button>
<div class="modal fade" id="complex" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Test</h4>
      </div>
      <div class="modal-body">
        <div class="table table-responsive">
          <table id="example">
            <thead>
              <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>ID Number</th>
                <th>Proband</th>
                <th>Gender</th>
                <th>Birth Date</th>
                <th>Life Status</th>
                <th>Phenotype</th>
                <th>Genotype</th>
                <th>&nbsp;</th>
              </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>