html - How can I animate individual links in a navbar? -
so i'm working on website , have navbar using html5 nav tags:
<nav class="contact"> <a href="#"><img src="images/twitter_icon.png"></a> <a href="#"><img src="images/insta_icon.png"></a> <a href="#"><img src="images/git_icon.png"></a> <a href="#"><img src="images/youtube_icon.png"></a> <a href="#"><img src="images/email_icon.png"></a> <a href="#"><img src="images/stack_icon.png"></a> </nav>
this inside main page div
now want animate these individual pictures when user hovers on them. came following, animating entire navbar:
nav { width: 100%; display: block; position: absolute; margin-top: 30px; } nav img { width: 40px; height: 40px; } nav a:hover img { animation-name: move; animation-duration: 0.2s; } @keyframes move{ from{margin-top: 0%;} to{margin-top: 10%;} } nav { display: inline-block; margin: 12px 0px 10px 20px; }
what doing wrong? i'm bit rusty these languages since haven't used them in while
it's because height of nav
changes when hover anchor (see demo). place them inline-blocks... therefor vertical aligned @ bottom.
add vertical-align: top
anchors, , works:
nav { width: 100%; display: block; position: absolute; margin-top: 30px; } nav img { width: 40px; height: 40px; } nav a:hover img { animation-name: move; animation-duration: 0.2s; } @keyframes move { { margin-top: 0%; } { margin-top: 10%; } } nav { display: inline-block; margin: 12px 0px 10px 20px; vertical-align: top; }
<nav class="contact"> <a href="#"><img src="images/twitter_icon.png"/></a> <a href="#"><img src="images/insta_icon.png"/></a> <a href="#"><img src="images/git_icon.png"/></a> <a href="#"><img src="images/youtube_icon.png"/></a> <a href="#"><img src="images/email_icon.png"/></a> <a href="#"><img src="images/stack_icon.png"/></a> </nav>
Comments
Post a Comment