Is it possible to create a button with a dropdown menu with just HTML & CSS?
<a id="TakeAction">Take Action</a>
<ul id="actions">
<li>action 1</li>
<li>action 2</li>
...
</ul>
When the link is clicked (hover is fine too, but click is preferred), I want ul#actions to show, where I can then chose my action. I tried to do something like this, but the menu (ul#actions) disappears when the cursor moves out of the button.
ul#actions
{
display:none;
}
#TakeAction:hover + ul#actions
{
display: block;
}
Do I need javascript/jquery to do something like this?
Try enclose it all in a div and put the hover on that div:
HTML:
<div class="actions">
<a id="TakeAction">Take Action</a>
<ul id="actions">
<li>action 1</li>
<li>action 2</li>
</ul>
</div>
CSS:
ul#actions
{
display:none;
}
.actions:hover ul#actions
{
display: block;
}
On hover: http://jsfiddle.net/gpf5n/
On click: http://jsfiddle.net/5p2SQ/
You can just use HTML Select Tag.
Here is my solution. Fiddle: Dropdown button with CSS
html
<select name='takeation'>
<option class='head'>Select Action</option>
<option value='Action 1'>Action 1</option>
<option value='Action 2'>Action 2</option>
<option value='Action 3'>Action 3</option>
</select>
css
option.head {
selected:selected;
display:none;
disabled:disabled;
}
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With