保持选择框大小可以修复添加选项

时间:2017-07-19 04:00:05

标签: javascript html css

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

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

我想保持盒子的大小。任何解决方案?

1 个答案:

答案 0 :(得分:0)

如果我理解,那就是你想要的。力量最大宽度和高度,任何变化。



.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>
&#13;
&#13;
&#13;