How to build a “visible on hover” action menu with CSS?
In my previous post I explain a way to build a “visible on hover” menu using jQuery.
Now, I’ll explain you how to do that without javascript, using only CSS.
First, built the web page and a CSS file
<html> <head> <title>Sam Beauvois | CSS on hover menu</title> <link href="demo.css" type="text/css" rel="stylesheet" /> </head> <body> <h2>Visible on hover with CSS demo.<h2> <h3>Please put you mouse hover the following texts</h3> <div> Demo 1 <div> <a href="#">action 1</a> | <a href="#">action 2</a> | <a href="#">action 3</a> </div> </div> </body>
Then add a class to the container and content divs
</pre> <div class="hidden_action_container"> Demo 1 <div class="hidden_action"> <a href="#">action 1</a> | <a href="#">action 2</a> | <a href="#">action 3</a> </div> </div> <pre>
And define the classes in the CSS file :
.hidden_action_container .hidden_action
{
display: none;
}
.hidden_action_container:hover .hidden_action
{
display:inline;
}
note the class declaration :
.hidden_action_container:hover .hidden_action
Add a style to make it nicer :
.hidden_action_container
{
padding : 15px 15px 15px 15px;
background-color: #DDDDDD;
border-style:solid;
border-color:#EEEEEE;
height:50px;
}
.hidden_action_container .hidden_action a
{
color:#999999;
font-size: 20px;
font-weight:bolder;
}
.hidden_action_container .hidden_action
{
display: none;
}
.hidden_action_container:hover .hidden_action
{
display:inline;
}
You can see the online demo here : http://www.sambeauvois.be/Demos/CSS/VisibleOnHover/demo.html

