I want to add padding to the options of html "select" tag.
I try to add it in the style property of "select" and "option" and it doesn't work in IE.
What can I do?
I want to add padding to the options of html "select" tag.
I try to add it in the style property of "select" and "option" and it doesn't work in IE.
What can I do?
It is difficult to style a drop down box cross browser. To get any sort of control, you'll need to code a replacement one in JavaScript. Be warned, however:
The following works, in FF3+ and Midori (and presumably other Webkit browsers):
select
{width: 14em;
margin: 0 1em;
text-indent: 1em;
line-height: 2em;}
select * {width: 14em;
padding: 0 1em;
text-indent: 0;
line-height: 2em;}
The width is to allow enough room in the displayed select
box when not active, the margin does what it always does, text-indent
is used to feign padding between the left boundary of the select box and the inner-text. line-height
is just to allow vertical spacing.
I can't comment on its use in IE, I'm afraid, so if anyone could feed back -or adapt- to suit that'd be good.
It's worth noting that the drop-down part of the select (select *
) isn't affected outside of FF3 for me, for whatever reason, so if that was the question you wanted answering, I apologise for offering nothing new.
Demo at: http://davidrhysthomas.co.uk/so/select-styling.html
OK, I hate to sound all 1990s, but would simply pre- and app-ending a space to the option text be acceptable for your desired goals?