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>

20100207_visibleOnHover_CSS_1Then 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

20100207_visibleOnHover_CSS_2
Now it’s functionnal,

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;
}

20100207_visibleOnHover_CSS_3You can see the online demo here : http://www.sambeauvois.be/Demos/CSS/VisibleOnHover/demo.html

Incoming search terms:

  • hover action css
  • Content Title Visible image hover css
  • HOvER ACTION
  • html text mouseover image
  • visible div link hover

About Sam Beauvois

Application Developer, .NET enthusiast since 2004, I'm interested in technology watch, usability, code quality, patterns & practices, UX, ...

1 comment

  1. [...] How to build a “visible on hover” action menu with jQuery ? Posted February 5th, 2010 in ASP.NET, Web development, jQuery by Sam Beauvois update 29/11/2010 : please notice that the same functionality could be achieved using css only [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>