Bootstrap - 调整模态的宽度以适合内容

时间:2016-11-02 19:15:48

标签: html css twitter-bootstrap

我只是想知道你是否可以调整模态的宽度以适应它的内容,而不必将width属性设置为固定值。我也不想放一个水平滚动条。我尝试设置overflow-x属性但没有成功。如果可能的话,我不想为此使用任何jQuery;只需更改CSS。这是screenshot

以下是代码:

<!-- Modal -->
<div class="modal fade" id="tableWorklog" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header"> <!--Modal Header -->
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Member name's Worklog</h4>
      </div> <!-- /header -->
<div class="modal-body"> <!--Modal Body -->
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Task Name</th>
                <th>Location</th>
                <th>Collab</th>
                <th>Description</th>
                <th>Start</th>
                <th>End</th>
                <th>Total</th>
                <th>Type</th>
                <th>Status</th>
                <th>Breaklog</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>task 1</td>
                <td>url</td>
                <td>NONE</td>
                <td>something about the task</td>
                <td>Date + time</td>
                <td>Date + time</td>
                <td><span class="label label-success">00:00:00</span></td>
                <td>Timer</td>
                <td><span class="label label-warning">ongoing</span></td>
                <td><span class="label label-danger">Breaklog(number)</span></td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>Total Hours</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>00:00:00</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
            </tr>
        </tfoot>
    </table>
</div> <!-- /body -->
      <div class="modal-footer"> <!-- Modal Footer -->
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div> <!-- /footer -->
    </div>
  </div>
</div> <!-- /modal -->

1 个答案:

答案 0 :(得分:2)

width: auto;应用于.modal-dialog元素应该这样做。

.modal-dialog {
  width: auto;
  max-width: 960px; // Optional, maximum width
}

JSFiddle Working Example