Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

Here's a little bit of CSS to create a button that expands when you hover over it. I used this over at travelblog.ws to create a 'Home' button that expands to allow the user to jump directly to specific parts of the home page. All of this is using pure CSS, no JavaScript required.

This is what the button looks like normally...
hoverbtn1.png


...and when I hover over it, it expands to show two additional detail buttons...
hoverbtn2.png


The cut down version of the CSS without all the additional styling is below, but first some HTML is required. The HTML below is cut down to the bare essentials so it won't look exactly like in the screenshot. There is an outer DIV element that has an inner DIV and a link, the inner DIV holds the detail links.
 HTML
<div class="tb_home_btn">
<div>
<a href="/home"><i class="fa fa-newspaper-o"></i></a>
<a href="/journeys"><i class="fa fa-map-o"></i></a>
</div>
<a href="/home"><i class="fa fa-home"></i></a>
</div>




Lets see the CSS that makes this possible...
 CSS
.tb_home_btn div {
display: none;
}
.tb_home_btn:hover div {
display: inline-block;
}


Now the CSS is cut down again to just the bare essentials so the border, padding, etc are not shown.

The way this works is by default the inner DIV is not shown, but when the mouse cursor hovers over the home button, the inner DIV is changed to be visible. Simple!

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.