使用列数时:2,如果有溢出,我想要显示一个垂直滚动条,但会出现一个水平滚动条。如果没有列数,则会出现垂直滚动条,如预期的那样。如何使用列数:2并显示垂直滚动条?
.searchCriteriaPanel {
border-radius: 0 0 5px 5px;
width: 300px;
height: 200px;
background-color: lightgrey;
padding: 10px;
overflow-y: auto;
column-count: 2;
}
<div id="MarketContent" class="searchCriteriaPanel">
<label><input type="checkbox">one</label><br />
<label><input type="checkbox">two</label><br />
<label><input type="checkbox">three</label><br />
<label><input type="checkbox">four</label><br />
<label><input type="checkbox">five</label><br />
<label><input type="checkbox">six</label><br />
<label><input type="checkbox">seven</label><br />
<label><input type="checkbox">eight</label><br />
<label><input type="checkbox">nine</label><br />
<label><input type="checkbox">ten</label><br />
<label><input type="checkbox">eleven</label><br />
<label><input type="checkbox">twelve</label><br />
<label><input type="checkbox">thirteen</label><br />
<label><input type="checkbox">fourteen</label><br />
<label><input type="checkbox">fifteen</label><br />
<label><input type="checkbox">sixteen</label><br />
<label><input type="checkbox">seventeen</label><br />
<label><input type="checkbox">eighteen</label><br />
<label><input type="checkbox">nineteen</label><br />
<label><input type="checkbox">twenty</label><br />
<label><input type="checkbox">twentyone</label><br />
<label><input type="checkbox">twentytwo</label>
</div>
答案 0 :(得分:1)
该行为的原因在于您使用已修复 width
和height
来限制该元素的大小。
为了得到你期望的,在它周围放一个包装元素,并将宽度和高度设置移动到这个包装器。然后,您将获得所需的诽谤行为:
.wrapper {
width: 300px;
height: 200px;
overflow: auto;
}
.searchCriteriaPanel {
border-radius: 0 0 5px 5px;
background-color: lightgrey;
padding: 10px;
column-count: 2;
}
小提琴中的完整解决方案:https://jsfiddle.net/jgLxc2fu/3/
答案 1 :(得分:0)
您是否尝试使用溢出控件包装列并在包装器上设置高度,例如: https://codepen.io/anon/pen/YrGPNM
.searchCriteriaPanel {
border-radius: 0 0 5px 5px;
width: 500px;
background-color: lightgrey;
padding: 10px;
column-count: 2;
}
.cont {
height: 100px;
overflow-y: auto;
}