4

For example,in the code,"option"is too low,I want to make it higher only with css(no javascript).

<select>
    <option>Beijing</option>
    <option>ShangHai</option>
    <option>WuHan</option>
  </select>
Ganesh Salunkhe
  • 596
  • 1
  • 4
  • 18
王晨阳
  • 41
  • 1
  • 1
  • 3

7 Answers7

3

Since that <option> (and <select>) elements are rendered by the browser as a dropdown list, unfortunately you cannot style them, because their style is only controlled by the browser itself.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
2

Change select > option to ul > li list and you can style as you want it yourself with Cross browser compatibility

Michal Kucaj
  • 681
  • 5
  • 15
1

You can use ul as alternative to style as you want, check this answer.

You can only make options bold or change the font-size, but it's not possible to change the space of the option.

option{font-size:20px;font-weight:bold;}
<select>
    <option>Beijing</option>
    <option>ShangHai</option>
    <option>WuHan</option>
  </select>

Options are rendered by the OS, not HTML, so the styling is limited.

Community
  • 1
  • 1
Nima
  • 2,100
  • 2
  • 23
  • 32
0

Try this:

option{
     padding:10px 0;
   }

JSFIDDLE DEMO

Also you can use the <optgroup> element to make it run in Chrome.

EDIT:-

Just saw that it is not reliable and cant be addressed perfectly for cross browser solutions.

MDN says:

Some elements simply can't be styled using CSS. These include all advanced user interface widgets such as range, color, or date controls as well as all the dropdown widgets, including , , and elements. The file picker widget is also known not to be stylable at all. The new and elements also fall in this category.

Alternative other than Javascript:

If possible then use Bootstrap's Dropdown.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

line-height can be useful -webkit-appearance: menulist-button this one can be used both will work

Sagar Naliyapara
  • 3,971
  • 5
  • 41
  • 61
0

If you're concerning about the mobile friendliness or the Google's mobile first SEO guidelines where the tappable items must not close to each other, then don't worry, modern mobile web browser will auto-adjust the item height for you.

Antonio Ooi
  • 1,601
  • 1
  • 18
  • 32
-1

Try This: change the height px to what you wish.

.a option { height: 50px; }
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Sonam
  • 2,322
  • 2
  • 13
  • 5