Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slide (animate) bg image position on navigation bar using CSS

I found this bit of code elsewhere on this forum and would like to know how I can get the same effect with a navigation bar.

So I would have 7 text links, and when you mouse over one, the image should slide to that bit of text. It would need to be in a different start position on each page (highlighting the current page on the nav bar)

This is the html:

<div class="box">
<a href"#">Home</a>
</div>

and the css:

.rollover a {
    background: url(img/bg_nav_slide.png) no-repeat 0px 0px;
    width: 920px;
    height: 50px;
    display: block;
}
.rollover a:hover {
    background-position: 0px 40px 0px 0px;
}   
.box {
    background: url(img/bg_nav_slide.png) no-repeat;;
    border: 0;
    width: 920px;
    height: 50px;    
    -webkit-transition: background 0.2s ease-in-out;
    -moz-transition: background 0.2s ease-in-out;
    transition: background 0.2s ease-in-out;
}
.box:hover {
    background-position: 40px 0;
}
.box p {
    text-indent: 2px;
}
like image 787
phatphish Avatar asked Nov 21 '25 07:11

phatphish


1 Answers

That's the Lavalamp effect; you can find a pure CSS solution here:

http://codepen.io/iamvdo/pen/GsIxk

like image 87
blend Avatar answered Nov 22 '25 20:11

blend