2017-07-19 75 views
0

我有這樣一個城市,選擇選擇選項: enter image description here保持選擇框的大小固定在添加選項

當我選擇多個城市這樣選擇的尺寸變大: enter image description here

我想保持盒子的大小修正。任何解決方案

+3

不知道你使用的是特定的JS框架或一些示例代碼,這將是很難看的替代品。但對於初學者,如果選擇的選項過多,則可以添加「overflow-y = auto」和「max-height」來獲取滾動條。 – Nisarg

回答

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>

相關問題