开发者

CSS hover issue using an odd navigation bar

I've been having a bit of an issue which is doing my head in. I know the way i'm doing this is wierd, and was likely to cause problems but I wanted to try it just using CSS. Ive got it quite close now but with an issue and was hoping someone might have an idea before i give up.

Basically I have a navigation bar that changes image on hover. The difference with this is that I wanted two images to change on the hover. So I decided that I could maybe do this by putting the two images into one larger one and overflowing the image outside of the hover link.

Now, it work开发者_StackOverflow中文版s somewhat, but you can over over the links from left to right and it displays the hovers fine, but if you do it from right to left it doesn't work.

Here is a link to the test http://www.pclwebdesign.co.uk/fruit

I have tried z indexing to bring the links ahead after thinking about it that obviously wouldnt work because the span is within it.

CSS

body{
    background:#FFF;
    }

#wrap{
    margin:0 auto;
    width:894px;
    height:900px;
    background:url(../images/background.jpg) no-repeat;
    }

#header{
    position:relative;
    margin:0 auto;
    width:625px;
    height:92px;
    }

#navbar{
    position:relative;
    display:block;
    margin-left:114px;
    width:626px;
    height:170px;
    background:url(../images/navbar2.jpg)
}

ul.cssmenu {    
list-style: none; padding-left: 24px; margin-top:-12px;     
}
.displace {    
position: absolute;    left: -5000px;     
}
ul.cssmenu li {    
float: left;    
}
ul.cssmenu li a {    
display: block; height: 170px;    
}

/**    Normal Links*/
ul.cssmenu li.about a {  
margin-right:10px; width:86px; height:59px;}
ul.cssmenu li.gallery a { width:120px; height:59px;}
ul.cssmenu li.home a {  width:150px; height:59px;}
ul.cssmenu li.contact a {  width:120px; height:59px;}
ul.cssmenu li.video a {  width:97px; height:59px;}

/**    Hidden LED Navbar images*/
ul.cssmenu li.about a .led {
    display: none; width:626px; height:170px; margin-left:-24px;}
ul.cssmenu li.gallery a .led {
    display: none; width:626px; height:170px; margin-left:-120px;}
ul.cssmenu li.home a .led {
    display: none; width:626px; height:170px; margin-left:-240px;}
ul.cssmenu li.contact a .led {
    display: none; width:626px; height:170px; margin-left:-390px;}
ul.cssmenu li.video a .led {
    display: none; width:626px; height:170px; margin-left:-510px; }


/**    Hover Links*/
ul.cssmenu li.about a:hover .led {
    display: block; width:626px; height:170px; margin-left:-24px; background:url(../images/navbar2.jpg); background-position: 0px -170px;    
    }
ul.cssmenu li.gallery a:hover .led {
    display: block; width:626px; height:170px; margin-left:-120px; background:url(../images/navbar2.jpg); background-position: 0px -340px;    
    }
ul.cssmenu li.home a:hover .led {
    display: block; width:626px; height:170px; margin-left:-240px; background:url(../images/navbar2.jpg); background-position: 0px -510px;    
    }
ul.cssmenu li.contact a:hover .led {
    display: block; width:626px; height:170px; margin-left:-390px; background:url(../images/navbar2.jpg); background-position: 0px -680px;    
    }
ul.cssmenu li.video a:hover .led {
    display: block; width:626px; height:170px; margin-left:-510px; background:url(../images/navbar2.jpg); background-position: 0px -850px;    
    }

/** Navigation bar finish */

HTML

<div id="wrap">
    <div id="header">
    </div>

    <div id="navbar">
      <ul class="cssmenu">
        <li class="about"><a href="about.htm" title="About"><span class="led"></span></a></li>

        <li class="gallery"><a href="gallery.htm" title="Gallery"><span class="led"></span></a></li>

        <li class="home"><a href="home.htm" title="Home"><span class="led"></span></a></li>

        <li class="contact"><a href="contact.htm" title="Contact"><span class="led"></span></a></li>

        <li class="video"><a href="video.htm" title="Video"><span class="led"></span></a></li>

      </ul>
    </div>


</div>


Have you tried looking into alternative methods for this? I think this would be a great opportunity to use some very simple jQuery. I did a quick draft of the code on jsfiddle http://jsfiddle.net/Ee37A/4/ for you to see. You would obviously need to style the divs and replace the text with your images, but I think this would be a much cleaner method to achieve what you're looking for.

Essentially, when you mouse over a div with the class ".about" (the nav button), the jQuery finds the div with class 'aboutPicture' (the led photo) and shows it. When your mouse leaves, the 'aboutPicture' div is hidden. I only programmed two different li, but you can use this as a basis.

You can find more about jQuery and download the source here: http://jQuery.com. You would want to create an external .js file to contain the functions that are shown on jsfiddle.net.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜