选择列表中的样式选项元素(添加填充和/或边距)
是否可以将选择列表/下拉列表的 option 元素设置为背景和字体之外的样式?我特别希望添加一些填充/边距,这样列表就不会那么拥挤。
Is it possible to style the option elements of a select list/dropdown beyond background and font? I'm specifically looking to add some padding/margins so the list isn't as cramped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要广泛的浏览器支持,则不可能。至少IE不支持。那么除了使用
和 JavaScript 的良好镜头来模仿并逐步增强下拉列表之外,别无选择。您可以在这里获取 JS 的一些想法(jQuery 实际上)基于下拉菜单。
Not possible if you want broad browser support. At least IE doesn't support it. There's then no other option than to mimic and progressively enhance the dropdown with
<ul><li>
and a good shot of JavaScript. You can get here some ideas what's possible with JS (jQuery actually) based dropdowns.@Alex:我们和你一样陷入了同样的困境。我们也想控制下拉菜单的用户界面。不幸的是,正如其他人已经提到的,如果您还想具有跨浏览器兼容性,则您无法选择系统下拉菜单。
所以我们想出了我们自己的 jQuery 插件,它的工作方式就像大多数功能的系统下拉菜单。它还支持主题以及通过模板提供自定义列表项的灵活性。您可以从以下列出的 URL 中查看正在运行的代码示例并了解更多信息。我们确信您会发现它很有用。
@Alex: we were in the same predicament as you seem to be. We too wanted to control the UI of the dropdown. Unfortunately as others have already mentioned, you have no option with the system dropdown if you want to have cross-browser compatibility also.
so we came up with our own jQuery plugin which works like a system dropdown for most features. It also supports themeing as well as flexibility to provide customized list items by way of templates. You can see the running code samples from the following URLs listed and learn more about it. We are sure you will find it useful.
有可能,但该功能在 Internet Explorer 中不可用
It is possible however the functionality is not available in Internet Explorer