Is there any way to add padding to select options via CSS?

后端 未结 2 890
生来不讨喜
生来不讨喜 2020-12-03 21:03

I want to add some kind of space (padding, margin or whatever) between select options in HTML using CSS. I am currently using Chrome and I\'ve already tried using something

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 21:34

    The appearance of option tags is determined by the browser in my experience and often for good reason - think about how differently the appearance is on iOS v chrome and the benefits of this.

    You can exert some control of the select element however, by using the browser prefixed appearance attribute.

    For example:

    select {
        padding: 2px 10px;
        border: 1px solid #979997;
    
        -webkit-appearance: none;
        -moz-appearance: none;
        -ms-appearance: none;
        -o-appearance: none;
        appearance: none;
    
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        -ms-border-radius: 4px;
        -o-border-radius: 4px;
        border-radius: 4px;
    }
    

    However when clicked, they appear as they normally do in whatever browser you're using.

    If you want finer control, your best bet I think is @sumitb.mdi's suggestion of a jquery plugin or build something similar yourself from scratch.

提交回复
热议问题