Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase height of a select?

Tags:

html

css

Without using any plugins, how can I increase the height of the <select> box in CSS?

I tried line-height but it didn't work for me.

like image 462
Jazmin Avatar asked Dec 18 '13 10:12

Jazmin


People also ask

How do you increase the size of a select box?

Answer: Use the CSS :focus pseudo-class By default the size of the <select> element is depend on the size of the largest <option> text. However, sometimes it is useful to set a fixed width to the select box and increase its size back to the original size when the user tries to select some option (i.e. on focus).

How do I increase the height of a dropdown box in HTML?

You just need to use the height CSS attribute for the select tag.

How do I style a selection dropdown in CSS?

There are many ways to design a <select> dropdown menu using CSS. The Dropdown Menu is mainly used to select an element from the list of elements. Each menu option can be defined by an <option> element that can nested inside the <select> element.

How do I change the default selection in CSS?

To hide the default arrow of the <select> dropdown, set the CSS appearance property to its "none" value, then add your individual arrow with the help of the background shorthand property.


4 Answers

I came across this other answer that actually works, if anyone chances across this question again.

How to standardize the height of a select box between Chrome and Firefox?

Basically you change the appearance definition of the element, then you can add style to it.

.className {
   -webkit-appearance: menulist-button;
   height: 50px;
}

Worked for me, but it does change the border on the element. Just be sure to cross-browser check it after the change and ensure the border styling is still acceptable.

like image 198
Vallier Avatar answered Oct 20 '22 18:10

Vallier


I hope this works for you

just give a height to the option in your stylesheet so that you can easily calculate the height of select field with the number of option rows

<style>
      select>option{ 
                   height:20px;
                 }
</style>

and add this function in your script tag as you desire or just copy this

<script>function myFunction() {
var x = document.getElementById("mySelect").length;
var y = 20 * x +10;
document.getElementById("mySelect").style.height = y+"px";}</script>

Body section

<body onload="myFunction()"><select id="mySelect" multiple="multiple"><option>Apple</option>option>Pear</option><option>Banana</option><option>Orange</option><option>Banana</option></select></body>
like image 37
prajun karn Avatar answered Oct 20 '22 17:10

prajun karn


For me this did the trick:

select {
    font: inherit;
}
like image 26
Florian Wendelborn Avatar answered Oct 20 '22 17:10

Florian Wendelborn


Since the priority is given to the inline-styling, you can use this trick to increase the height of your select list. All you have to do is add inline-style in the select tag.

<!-----------If you are using Bootstrap ---------->

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body>

<div class="container">
  <form>
    <div class="form-group">
      <label for="sel1">Select list (select one):</label>
      <select class="form-control" style=" height:50px;" id="sel1">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
      </select>
      </div>
    </form>
  </div>
  </body>
  
like image 1
Shalinee SIngh Avatar answered Oct 20 '22 18:10

Shalinee SIngh