自定义 HTML <选择>与CSS

发布于 2024-12-16 11:34:29 字数 448 浏览 2 评论 0 原文

可能的重复:
是否可以设置选择框的样式?

我是寻找一种在我的 HTML 代码中自定义选择元素的方法。 我希望我的选择看起来像这样:

在此处输入图像描述

我希望用户能够看到一个图像和两个文本,它代表我的列表的第一个元素。由于这应该通过智能手机(Android 和 Blackberry)访问,我相信该列表将在操作系统组件中打开,因此我不必费心设计我选择的其余选项,对吧? 实现这一目标的最佳方法是什么?

预先非常感谢!

Possible Duplicate:
Is it possible to style a select box?

I'm searching for a way to customize a select element in my HTML code.
I wanted my select to look like this:

enter image description here

I want the user to be able to see an image and two texts, which represents the first element of my list. Since this is supposed to be accessed by a smartphone (Android and Blackberry), I believe the list will open in the operating system component, so I don't have to bother styling the remaining options of my select, right?
What is the best way to accomplish this?

Thanks a lot in advance!

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

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

发布评论

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

评论(6

茶底世界 2024-12-23 11:34:29

我认为仅通过 css 样式化

我建议使用其他元素,例如

来完成你想要的,以及一点 javascript (jQuery, MooTools)以获得附加效果。

I don't think you can accomplish quite as much as you want with just css styling a <select> tag. This is about how far it goes: http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/

I would suggest using other elements, like <div>s to accomplish what you want, and a little bit of javascript (jQuery, MooTools) for the added effects.

漫漫岁月 2024-12-23 11:34:29

看来您需要一个 JavaScript 图像组合框。这篇文章非常简单,我相信您可以比文章中所写的内容进一步定制它。试一试吧! :-)

It seems like you need a JavaScript image combobox. The article is pretty straightforward, and i believe you can customize it even further than whats written in the article. Give it a shot! :-)

夏天碎花小短裙 2024-12-23 11:34:29

我使用jQuery插件prettySelectBox,推荐它。 http://abeautifulsite.net/blog/2011/01/jquery-selectbox-插件/

I use jQuery plugin prettySelectBox, recommend it. http://abeautifulsite.net/blog/2011/01/jquery-selectbox-plugin/

挽你眉间 2024-12-23 11:34:29

样式选择是出了名的困难 - 浏览器供应商不允许在表单元素上广泛使用自定义样式。

解决这个问题的一种方法是使用 javascript,也许使用 jQuery 等库。

此页面上有一些很好的答案和插件链接:
是否可以设置选择框的样式?

Styling selects is notoriously difficult - browser vendors have not allowed for widespread custom styling on form elements.

One way to get around it is to use javascript, maybe with a library such as jQuery.

There's some good answers and links to plugins on this page:
Is it possible to style a select box?

﹉夏雨初晴づ 2024-12-23 11:34:29

HTML 标签、

HTML <select> tag is part of a larger set, called HTML form controls. They are different types of <input> tag, <select> tag, <textarea>. The most common known issues of HTML form elements (controls) is that, they don't have cross-browser look & feel. In other words, while a browser may animate a drop-down menu (a select element), another browser may open it up abruptly and at-once. Thus, a known web-design and development practice, is to create your custom controls, from scratch using simple elements and JavaScript (usually jQuery). Thus, I recommend that you create it on your own, instead of trying to find out how to make what you want (and to be honest, I think what you're looking for is not possible, since nesting block-level elements inside <option> tags are not allowed, if you want to have valid HTML).

一场春暖 2024-12-23 11:34:29

选择的元素是那些接受较少定制的元素,因此您设计它们的自由度非常有限。

为了实现您想要的目标,我建议您使用自定义 HTML、JavaScript 和 CSS 构建自己的类似选择的组件。

如果您想使用已有的链接,我建议您查看以下链接:

但是,因为你正在寻找什么因为太具体了,您可能需要自己创建下拉菜单。

Select elements are the ones which less customization acepts, so your freedom to style them is very limited.

In order to achive what you are looking for, I suggest you to build your own select-like component using custom HTML, JavaScript and CSS.

If you want to use an already existing one, I suggest you to take a look at the following links:

However, since what you are looking for is too specific, probably you will need to create your dropdown in your own.

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