选择和选项样式
如何设置选择选项的样式?我想要在下拉菜单中交替背景颜色。
How to style the select options? I want alternating background colors in the drop down menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何设置选择选项的样式?我想要在下拉菜单中交替背景颜色。
How to style the select options? I want alternating background colors in the drop down menu.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
就像任何其他元素一样,
如果您需要支持不支持
nth-child
的浏览器,您将需要使用一个类。有些浏览器根本不支持样式选项(猜猜是哪些)。
Just like any other element
If you need to support browsers that don't support
nth-child
you'll need to use a class.Some browsers don't support styling
option
s at all (guess which ones).好的,如果这是 HTML/CSS 的方式,我不妨建议一个很棒的 jQuery UI 插件,名为 UI 选择菜单。这是迄今为止我所见过的精选菜单中最美妙的事情。我打赌你可以用它轻松实现交替选项颜色。
但可以公平地说,这个插件正处于开发阶段 - 谨慎行事!
OK, if this is going the way of HTML/CSS, I might as well suggest a wonderful jQuery UI plugin called UI Selectmenu. It is the most wonderful thing I have seen about select menus so far. I bet you could easily implement alternating option colors with it.
But it's fair to say that this plugin is in development stage - proceed with caution!
只需添加尺寸属性和选择标签即可。示例 select size="4",其中 4 是要显示的选项数。
Just add size attribute along with select tag. Example select size="4", where 4 is the no of options to be displayed.