On my personal website, I have implemented the CSS3 Transition property on the top navigation to create an animation effect on an element with a border. This effect causes the border to swell when hovered over.
Here is the relevant markup:
<nav>
<a class="email" href="mailto:notmyrealemailaddress">
<div class="icon-border">
<img src="images/mail_icon.png" width="14" height="12">
</div>Email Me</a>
<a class="phone" href="tel:4075555555">
<div class="icon-border">
<img src="images/phone_icon.png" width="11" height="18">
</div>Call Me</a>
<a class="behance" href="http://behance.net/dannymcgee" target="_blank">
<div class="icon-border">
<img src="images/behance_icon.png" width="21" height="13">
</div>See My Work</a>
</nav>
CSS:
header nav .icon-border {
display: inline-block;
border: 2px solid #000;
border-radius: 30px;
padding: 5px;
margin: 0 10px;
transition: 0.15s padding ease-out, 0.15s margin ease-out, 0.15s border ease-out;
}
header nav a:hover .icon-border {
padding: 10px;
margin: -10px 5px;
border: 2px solid #ddd;
transition: 0.15s padding ease-out, 0.15s margin ease-out, 0.15s border ease-out;
}
By adjusting margins and padding on hover, the circular border of the element expands without affecting the position of the enclosed image. However, there is an issue when quickly moving the mouse between certain links, causing the navigation to "jump" slightly. This problem can likely be resolved. Any suggestions?