I've seen this very simple selectbox on youtube, where the select options are visible on hover (instead of clicking), as seen in following screenshot.
I'm trying to create similar effect in the following simple select box. Can someone please help how this can be done? Thanks.
<select name="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
At work at the moment so can't check youtube but from the styling I am guessing that that "select" control is not an actual select control. Most likely it is implemented like a navigational drop down menu but instead of navigating to a url on click it replaces the contents and value of an input label. Then on form submit it can pick up the value of the label.
It is impossible to open a
select
box in the plain way your are describing. It is no coincidence that the image you have provided looks nothing like a normal select box. This is because it is probably actually aul
list which is styled to look as it does, revealing itself on hover, which is actually possible.I created an example over on jsfiddle of how it could be done.
Link to the updated jquery plugin Forked $.selectUI plugin
If you're interested in doing it this way, I've got a simple, non-javascript way of doing it on my current project actually (look at the "I Want To" menu at the top). Like @Marcus said, this is not with a select box, but is done with a unordered list (
<ul>
).The html is straightforward:
the important part is the css, essentially just the first 2 rules. The div appears to expand because of the
overflow:visible
on:hover
.Here's one way of doing it, though I'd prefer a more plug-in approach (rather than hard-coding the html
ul
):JS Fiddle demo.
Edited to include an
alert
demonstrating the changes in theselect
element's value: JS Fiddle demo.Edited to include the css and html used in the demo:
html
css:
This causes the menu to hide the
unselected
items until theul
is hovered over, then revealing all the options, and uses theclick()
event to assign theunselected
class name to the non-clicked elements; which allows the clicked element to be still visible on mouseout.The above CSS reflects the most-recent edit, to make the currently-selected, and
:hover
-ed,li
more visible.Latest JS Fiddle demo.
Edited because, well, I got a little bored. And had nothing better to do, so I made a simple plug-in:
JS Fiddle demo, including the 'plug-in'.
Notes:
select
(which you can certainly do, and works okay) it does screw with the page-flow a little (or a lot), but this can be amended in the CSS (I'd imagine, though I've not yet tried).dl
elements to be used in place of the currentul
, which would allow for giving an explanation of the available options.Edited because I felt that there should be a visible 'guidance' element, and also to try and explain something of how it all works.
Given the html:
Use the jQuery to call the plugin:
This takes the above select, and creates a
ul
with the following mark-up:The CSS used (in the demo):
JS Fiddle demo.