[英]How to add vertical scroll only for selected div inside bootstrap modal?
I have 2 div
in bootstrap modal separated by col-8
and col-4
.Here how can I add vertical scroll only for col-4
div? 我有2个
div
在bootstrap模式中由col-8
和col-4
分隔。这里我怎样才能为col-4
div添加垂直滚动?
/* .addScroll{ overflow-y:auto; } */ /* .modal-body{ overflow-y:auto; } */
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container"> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <div class="col-xs- 8 col-sm-8 col-md-8 col-lg-8">In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet-based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990.</div> <div class="col-xs- 4 col-sm-4 col-md-4 col-lg-4 addScroll">In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet-based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990.</div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div>
I can add vertical-scroll
for complete modal-body
. 我可以为完整的
modal-body
添加vertical-scroll
。 But I want to add only for col-4
div. 但我想只为
col-4
div添加。 Any suggestion? 有什么建议吗?
https://jsfiddle.net/et5b274h/ https://jsfiddle.net/et5b274h/
Add .addScroll
div inside .col-sm-4
div set height of it with overflow-y element 在
.col-sm-4
div中添加.addScroll
div使用overflow-y元素设置它的高度
.addScroll{ overflow-y:auto; height: 200px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-xs- 8 col-sm-8 col-md-8 col-lg-8">In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet-based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990.</div> <div class="col-xs- 4 col-sm-4 col-md-4 col-lg-4"> <div class=" addScroll"> In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet-based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990. </div> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div>
You can use the following CSS rules: 您可以使用以下CSS规则:
.addScroll {
overflow-y: auto;
max-height: 140px;
}
If you will not specify height
or max-height
of .addScroll
element (or one of the parent elements will not limit its height), it will take as much height as content, and the scroll will not be applied. 如果您不指定
.addScroll
元素的height
或max-height
(或其中一个父元素不会限制其高度),则它将占用内容的高度,并且不会应用滚动。 But if you will specify for example max-height: 140px;
但是如果你要指定例如
max-height: 140px;
(the same height as the other div
), the scroll will be applied. (与其他
div
高度相同),将应用滚动。
Here is the working fiddle: https://jsfiddle.net/et5b274h/1/ 这是工作小提琴: https : //jsfiddle.net/et5b274h/1/
Please check https://jsfiddle.net/et5b274h/8/ and see if this is what you want. 请检查https://jsfiddle.net/et5b274h/8/ ,看看这是否是你想要的。 I have added a div with class row inside modal-content.
我在modal-content中添加了一个带有类行的div 。
<div class="container">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-8 col-ld-8 col-xs-8">
11one one one one one one one one
</div>
<div class="col-md-4 col-ld-4 col-xs-4">
<div style="width: 100%; height: 100px; overflow-y: scroll; overflow-x: hidden">
22two
<br/> two
<br/> two
<br/> two
<br/> two
<br/> two
<br/> two two two
</div>
<div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
You can use CSS
overflow-y: scroll;height: 120px
to your inner div
( col-md-4
). 你可以使用
CSS
overflow-y: scroll;height: 120px
到你的内部div
( col-md-4
)。
If you use auto
instead of scroll
it will add scroll whenever necessary. 如果您使用
auto
而不是scroll
,它将在必要时添加滚动。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <div class="col-xs- 8 col-sm-8 col-md-8 col-lg-8">In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet-based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990.</div> <div style="overflow-y: scroll;height: 120px;" class="col-xs- 4 col-sm-4 col-md-4 col-lg-4 vertical-scroll addScroll">In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a system for CERN researchers to use and shar CERN researchers to use and shar CERN researchers to use and shar CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing adsfdsfdsfdsfdsfsdfds edsfsdfn Internet-based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990.</div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.