Share via


CSS Hover Trick

In no way am I claiming this to be original.  But I can’t say I have seen this trick done anywhere else.  With the CSS :hover selector, you can create a nice “status message” appear in one location while hovering over particular items in a list (or menu).  Below are the screen captures of what the trick accomplishes, followed by the entire source code to make it possible.  Enjoy!

csshover00 
No mouse hover

 

csshover01
Mouse hover over first item

 

csshover02
Mouse hover over second item

 

csshover03
Mouse hover over third item

 

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>CSS Hover</title>
    <style>
        #csshover ul { 
            position:           relative;
            margin:             0;
            padding:            0; 
        }        
        #csshover li {
            list-style-type:    none;
            display:            inline-block;
            margin-right:       3em;  
            cursor:             pointer;   
        }
        #csshover li p {
            position:           absolute;
            top:                2em;   
            display:            none;
            left:               0em;
        }
        #csshover li:hover p {
            display:            inherit;
        }
    </style>
</head>
<body>
    <article id="csshover">
        <h1>CSS Hover Trick</h1>
        <p>Hover over each of the words below.  Look for status message below!</p>
        <ul>
            <li><div>CSS  </div><p>It's all about the style!</p></li>
            <li><div>Hover</div><p>When you wander above...</p></li>
            <li><div>Trick</div><p>Look Ma, no JavaScript!</p></li>
        </ul>
    </article>
</body>
</html>