IE8 - Vertical alignment of a <select> element with a custom height

陌路散爱 提交于 2019-12-24 00:42:57

问题


When applying a custom height on a select element, the text in IE8 is being vertically aligned to the bottom: http://jsfiddle.net/4DYPf/8/

<select>
    <option value="1">123</option>
    <option value="1">456</option>
</select>

select
{
   border: 2px solid #CDCDCD;
   height: 50px;   
}

Is there a way to align in to the middle?


回答1:


This is no a css answer, but if you really need to center the text and you use jQuery, this is a way to fake that alignment:
http://jsfiddle.net/cadence96/7MZHv/1/
It consists of placing an absoluted span over the white space of the select tag, then the current text of the selected option will be inserted within this span. That way you can style its text the way you want.




回答2:


If you add padding:1em 0px; to your select style it vertically aligns your text to the middle but also squashes the drop down arrow.

See example:http://jsfiddle.net/TfwsE/1/



来源:https://stackoverflow.com/questions/9200618/ie8-vertical-alignment-of-a-select-element-with-a-custom-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!