修复 <Pre> 的大小并使 html 可滚动

Fix the size of <Pre> and make scrollable in html

我用 < Pre > 在 Modal 中显示我的 json 数据。但是

根据json大小变成了不同的大小。我想修复 
 高度。如果 json 较大,则滚动显示。 

这是我的模态框。

<div class="modal-content json-modal-body" id="full-width" ng-controller="projectdetailsController">

    <div class="modal-header modal-header-confirm">
        <h4 class="modal-title ng-binding">
            <span class="glyphicon glyphicon-indent-left"></span>{{modalOptions.headerText}}
        </h4>
    </div>

    <div class="modal-body"> 

         <pre ng-bind-html="json | prettifyFilter"></pre>

    </div>

</div>

当json为空时。变成这样

我该怎么做?

试试这个:

<style>
 div.scroll {
    width: 100px;
    height: 100px;
    overflow: scroll;
 }
</style>

看,这是否解决了您的问题。

您可以设置一些宽度、高度并强制它始终显示滚动条

  .modal-body pre {
    height: 200px;/*something like 90% would work too if parent's height is specified*/
    width: 300px;
    word-wrap: break-word;/*if you want to prevent horizontal scrolling and wrap text instead*/
    overflow: scroll;/*forces scroll to always show; if overflow: auto scroll will be visible only if needed*/
  }