Dropdown Selection with Images
You're looking to create a dropdown select that displays images instead of text. While the jQuery combobox is often suggested, it still requires text alongside the images.
Solution: Replace Text with Images
Surprisingly, you can achieve this dropdown menu without JavaScript! Here's how:
HTML Structure
Use radio buttons and labels:
<div>
CSS Styling
Style them using CSS. Hide the radio buttons, style the labels to look like dropdown options, and make the dropdown expand on hover.
#image-dropdown { /* Style the "box" in its minimized state */ ... } #image-dropdown:hover { /* When expanded, the dropdown will get native means of scrolling */ ... } #image-dropdown input { /* Hide the nasty default radio buttons */ ... } #image-dropdown label { /* Style the labels to look like dropdown options */ ... } ... #image-dropdown input:checked + label { /* Make the selected option visible in the collapsed menu */ ... }
Functionality
Radio buttons are linked to labels such that clicking a label activates the corresponding radio button. When you hover over the dropdown, it expands, showing all the image options. The selected image remains visible even in the collapsed state.
Example
See the full example at: http://jsfiddle.net/NDCSR/1/
Implementation Details
The above is the detailed content of How to Create a Dropdown Menu with Images Instead of Text?. For more information, please follow other related articles on the PHP Chinese website!