How do I select from a list of image options?
P粉974462439
2023-08-01 18:01:00
<p>I am trying to implement a design where the select input displays a list of images to pick from. </p>
<pre class="brush:php;toolbar:false;"><select name="choose-image">
<option value="" disabled selected>Choose your image</option>
<option value="Smiling"><img src={image} alt="local-avatar" /></option>
<option value="Sad">Sad</option>
</select></pre>
<p>The second option doesn't display anything and even if it does, I need to style the dropdown and I'm still not sure how. Thanks for any help. Thanks. </p>
Direct use of images in element tags is not supported in HTML. The reason the second option doesn't display anything is that the
tag is intended to be plain text, not an HTML element. To implement a design where you want to display a list of images for selection, you can use a custom selection dropdown menu using HTML, CSS, and JavaScript. There are several libraries and plugins available that can help you achieve this, such as Select2, Chosen or a custom implementation using CSS and JavaScript. Here is an example of how to create a custom selection drop-down menu using images:
HTML
CSS:
JavaScript :
In this example, you can replace {image_url} with the actual url of the image you want to display. When the user clicks on the custom selection it will display a list of images and when the user selects an image it will update the selected option accordingly. Keep in mind that this is a basic example and you may need to adjust the CSS and JavaScript based on your specific needs and styling preferences. Additionally, for more complex applications, consider using front-end frameworks such as React or Vue.js.