Html 添加带有选项标签的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5562149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding images with option tag
提问by enthusiastic
I have a drop down list. I want to add images along with it. I tried adding img
tag inside tha option
tag... But still the images are not getting displayed.
How do I do it using option
tag?
我有一个下拉列表。我想同时添加图像。我尝试img
在 tha 标签内添加标签option
......但图像仍然没有显示。我如何使用option
标签做到这一点?
回答by BoltClock
It's not possible, as <option>
only supports text.
这是不可能的,因为<option>
只支持 text。
You may have to roll your own drop-down control using complex HTML/CSS/JavaScript. How to do it may or may not be within the scope of your question.
您可能必须使用复杂的 HTML/CSS/JavaScript 滚动您自己的下拉控件。如何做到这一点可能在您的问题范围内,也可能不在。
Alternatively, you may use a non-repeating background-image
and apply some padding on the text to achieve a similar effect. But if each <option>
is to have a unique image, your code is going to be polluted with a style
attribute for every single <option>
. If you don't mind that, it's fine. Otherwise, roll your own somehow.
或者,您可以使用非重复background-image
并在文本上应用一些填充来实现类似的效果。但是,如果每个<option>
图像都具有唯一的图像,那么您的代码将被style
每个<option>
. 如果你不介意,没关系。否则,以某种方式推出自己的产品。