There is a hover CSS state is it possible to also add a CSS click state?
In the example the browser responds to a mouse hover event and apply specific styles then. Can you do the same on click event?
Supported:
#menu:hover
No response:
#menu:click
.menu {
display: none;
}
.menu li:hover {
background-color: lightgray;
}
button {
padding: 12px;
}
#hoverMenu {
position: relative;
display: inline-block;
}
#hoverMenu:hover .menu {
display: block;
}
#clickMenu {
position: relative;
display: block;
}
#clickMenu:click .menu {
display: block;
}
<div id="hoverMenu">
<button>Menu on hover</button>
<ul class="menu">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
<div id="clickMenu">
<button>Menu on click</button>
<ul class="menu">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
Use cases:
- when you want menus to show on click rather than on hover
- when you want to show pop overs that are appropriate to show on click rather than show on hover.
- when you are not able to use JavaScript or when it would be unnecessary
Does anyone else want to see this in the CSS spec?