我見過這麼多人問這個問題,但沒有真正可靠的答案。如果高度超過瀏覽器,設置Bootstrap模態內容滾動
如果模態的高度超過瀏覽器的內高,我希望紅邊的Div有一個滾動條來保持瀏覽器視圖中的模態。
#scrollbox {
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<input type="button" data-toggle="modal" data-target="#myModal" value="Launch 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-body">
Hello, below is some text in a div that should start scrolling if the height of the modal exceeds the browser.
<p><div id="scrollbox">
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
</div>
</div>
</div>
</div>
</div>
謝謝,只需要將CSS'height'更改爲'max-height' :-) –
@DanielWilliams完成:) –
另外,我從來沒有見過這個'100vh'。我一直使用'calc(100%-'。 –