How to add vertical scrollbar to select box options list?
Try something like this (Replace the number 3 with the number of items you would like to show):
<select onfocus='this.size=3;' onblur='this.size=1;' onchange='this.size=1; this.blur();'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
</select>
Overflow-y
doesn't work on select boxes. What I would recommend using is size
on your select box. In my example I've used 5 as the value, you can obviously change this to your liking.
.wrapper{
width:200px;
padding:20px;
height: 150px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="wrapper"><select name="" id="" class="form-control" onfocus='this.size=5;' onblur='this.size=1;' onchange='this.size=1; this.blur();'>
<option value="">One</option>
<option value="">Two</option>
<option value="">Three</option>
<option value="">Four</option>
<option value="">Five</option>
<option value="">Six</option>
<option value="">Seven</option>
<option value="">Eight</option>
<option value="">Nine</option>
<option value="">Ten</option>
</select></div>
Edit: Amended my answer to include some js to provide OP with the desired result.
Just add size attribute in your select. For ex:- size="5"
.wrapper{
width:200px;
padding:20px;
height: 150px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="wrapper" >
<select size="5" name="" id="" class="form-control">
<option value="">One</option>
<option value="">Two</option>
<option value="">Three</option>
<option value="">Four</option>
<option value="">Five</option>
<option value="">Six</option>
<option value="">Seven</option>
<option value="">Eight</option>
<option value="">Nine</option>
<option value="">Ten</option>
</select></div>