选择和选项样式

发布于 2024-09-06 21:02:56 字数 35 浏览 2 评论 0原文

如何设置选择选项的样式?我想要在下拉菜单中交替背景颜色。

How to style the select options? I want alternating background colors in the drop down menu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九命猫 2024-09-13 21:02:56

就像任何其他元素一样,

option:nth-child(even) {
  background-color: red;
}

option:nth-child(odd) {
  background-color: blue;
}

如果您需要支持不支持nth-child的浏览器,您将需要使用一个类。

有些浏览器根本不支持样式选项(猜猜是哪些)。

Just like any other element

option:nth-child(even) {
  background-color: red;
}

option:nth-child(odd) {
  background-color: blue;
}

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 options at all (guess which ones).

仄言 2024-09-13 21:02:56

好的,如果这是 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!

姐不稀罕 2024-09-13 21:02:56

只需添加尺寸属性和选择标签即可。示例 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文