gpt4 book ai didi

javascript - 在添加选项时保持选择框大小固定

转载 作者:行者123 更新时间:2023-11-28 03:21:40 29 4
gpt4 key购买 nike

我有一个城市选择器选择选项,例如: enter image description here

当我选择多个城市时,选择器的大小会像这样增加: enter image description here

我想保持盒子的尺寸固定。有什么解决办法吗?

最佳答案

如果我明白了,那就是你想要的。具有任何变化的力最大宽度和高度。

.select {
/** Want to have permanant width 150px **/
width:150px;
max-width:150px;
background:lightblue;
padding:3px;
height:150px;
overflow-y:auto;
/** the magic think **/
word-break:break-word;
}

.option {
background:tomato;
width:100%; /** or display block in your case (for the tags selected) **/
}

.option:nth-child(odd) {
background:lightgreen;
}
<div class="select">
<div class="option">testttt</div>
<div class="option">testtttttttttttttttesttttttttttttttttesttttttttttttttt</div>
<div class="option">testttttttttttttttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
<div class="option">testttt</div>
</div>

关于javascript - 在添加选项时保持选择框大小固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180723/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com