【发布时间】:2020-03-18 21:20:50
【问题描述】:
我正在编写一个大表单,为了避免出现一个巨大的滚动,我使用overflow:auto 将它分割并嵌套到div 中。 这样我就可以将我的表单分解成几个窗口,每个窗口都有固定的高度和滚动条。
I'm trying to use the select2 plugin, but when the select is hidden in one of my windows, I'm getting a scrollbar to reach it, which is ok, but I'm also getting a scrollbar on the main窗口,而我正是试图避免这种情况。
我在下面做了一个sn-p,有什么线索吗?谢谢!
$('select[name="test"]').select2();
.wrapper {
height: 100vh;
width: 300px;
background-color: #ddd;
overflow: auto;
}
.scrollingBlock {
height: 100%;
width: 75%;
background-color: #ccc;
}
.bigElement {
height: 150%;
width: 75%;
background-color: #c00;
}
.elementWithSelect {
width: 75%;
background-color: #0c0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet"/>
<div class="wrapper">
<div class="scrollingBlock">
<div class="bigElement"></div>
<div class="elementWithSelect">
<div class="selectWrapper">
<select name="test">
<option value="c1">Choice 1</option>
<option value="c2">Choice 2</option>
<option value="c3">Choice 3</option>
<option value="c4">Choice 4</option>
<option value="c5">Choice 5</option>
</select>
</div>
</div>
</div>
</div>
【问题讨论】:
标签: css jquery-select2