首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在引导模式中只为选定的div添加垂直滚动?

如何在引导模式中只为选定的div添加垂直滚动?
EN

Stack Overflow用户
提问于 2017-11-06 05:15:59
回答 4查看 11.6K关注 0票数 5

我在引导模式中有2 div,由col-8col-4.Here分隔,如何只为col-4 div添加垂直滚动?

代码语言:javascript
复制
/* .addScroll{
  overflow-y:auto;
} */
/* .modal-body{
 overflow-y:auto;
} */
代码语言:javascript
复制
<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">&times;</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>

我可以为完整的vertical-scroll添加modal-body。但我只想为col-4 div添加。有什么建议吗?

https://jsfiddle.net/et5b274h/

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-11-06 05:20:09

.addScroll div设置高度中添加.col-sm-4 div,其中包含溢出-y元素。

代码语言:javascript
复制
.addScroll{
  overflow-y:auto;
  height: 200px;
}
代码语言:javascript
复制
<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">&times;</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>

票数 4
EN

Stack Overflow用户

发布于 2017-11-06 05:22:44

您可以使用以下CSS规则:

代码语言:javascript
复制
.addScroll {
  overflow-y: auto;
  max-height: 140px;
}

如果您不指定heightmax-height of .addScroll元素(或者父元素之一不会限制其高度),它将占用与内容相同的高度,并且滚动卷将不会被应用。但是,如果要指定max-height: 140px; (与其他div相同的高度),则将应用滚动。

下面是工作小提琴:https://jsfiddle.net/et5b274h/1/

票数 3
EN

Stack Overflow用户

发布于 2017-11-06 05:34:50

请检查https://jsfiddle.net/et5b274h/8/,看看这是否是你想要的。我在模态内容中添加了一个带有类行的div。

代码语言:javascript
复制
<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">&times;</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>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47130148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档