I want to vertical-align text in select box

前端 未结 16 1289
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 00:25

I want to vertically align the text in select box. I tried using

select{
   verticle-align:middle;
}

however it does not work in any brows

16条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 01:12

    I found that simply setting the line-height and height to the same pixel quantity produced the most consistent result. By "most consistent" I mean optimally consistent but of course it is not 100% "pixel-perfect" across browsers. Additionally I found that Firefox (v. 17.x) tends to crowd the option text to the right against the drop-down arrow; I alleviated this with a small amount of padding-right set on the OPTION element only. This setting does not affect appearance in IE 7-9.

    My result:

    select, option {
        font-size:10px;
        height:19px;
        line-height: 19px;
        padding:0;
        margin:0;
    }
    
    option {
        padding-right:6px; /* Firefox */
    }
    

    NOTE -- my SELECT element uses a smaller font, 10px. Obviously you will need to adjust proportions accordingly for your specific UI context.

提交回复
热议问题