Web Design Forum: TUTORIAL: CSS image rollover - horizontal navigation - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

TUTORIAL: CSS image rollover - horizontal navigation A simple CSS rollover tutorial using only one image Rate Topic: -----

#41 User is offline   krakatoa 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 28-November 08
  • Reputation: 0
  • Experience:Advanced
  • Area of Expertise:Web Designer

  Posted 28 November 2008 - 11:38 AM

Here's an easy method to create CSS rollovers (in this example b1.gif and b2.gif are the two button states):

<style>
img.nohover {border:0}
img.hover {border:0;display:none}
A:hover img.hover {display:inline}
A:hover img.nohover {display:none}
</style>
<A HREF="#">
<img src="b1.gif" class="nohover">
<img src="b2.gif" class="hover">
</A>

0

#42 User is offline   Kannan 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 28
  • Joined: 05-February 09
  • Reputation: 0
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 08 February 2009 - 06:06 PM

Thkz Ben and ErisDS....it really helped me a lot... :good: :yahoo:
0

#43 User is offline   Neji 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 204
  • Joined: 26-February 09
  • Reputation: 20
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 13 March 2009 - 10:54 PM

Thanks for posting this.

I have one problem which I hope someone can help me with. I'm using this code but I have the nav bar in the center of the page. It is basically the same as the original but a different graphics, obviously. I'm trying to get the bar to extend to the side of the browser, no matter what resolution/size the user is using. I thought of using a background image that repeats but this code already uses a background image.

How can I make this happen using CSS?
0

#44 User is offline   Ben 

  • Web Designer Forum Admin
  • View gallery
  • Group: Root Admin
  • Posts: 2,840
  • Joined: 24-August 06
  • Reputation: 102
  • Gender:Male
  • Location:Essex, UK
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 13 March 2009 - 11:05 PM

Hi,

Thanks for the comments. :)

You can apply a background colour with an image e.g. { background: #ccc url(menu.jpg) no-repeat 0 0; width 100%} - you'll need to set the position/repeat properties as you have to sit image centrally, but the #ccc - part means the background colour will span 100% width whilst keeping the main navigation images centrally.

Is that what you mean? If not, post the code you have and i'll try and assist you :)
0

#45 User is offline   Neji 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 204
  • Joined: 26-February 09
  • Reputation: 20
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 13 March 2009 - 11:14 PM

http://www.fmlbadges...test/index.html

That is the site, if you look at my code, I did it by making a background of the image. That probably isn't a good way of doing it :rolleyes:

You can see that the extensions of the menu bar would be an image. Hope that makes sense.

Thanks for the quick reply, btw.
0

#46 User is offline   Ben 

  • Web Designer Forum Admin
  • View gallery
  • Group: Root Admin
  • Posts: 2,840
  • Joined: 24-August 06
  • Reputation: 102
  • Gender:Male
  • Location:Essex, UK
  • Experience:Intermediate
  • Area of Expertise:Web Designer

  Posted 13 March 2009 - 11:26 PM

View PostNeji, on Mar 13 2009, 23:14, said:

Thanks for the quick reply, btw.


No trouble, ok i've checked out your site, the nav grey bar is spanning 100% width with the actual nav buttons sitting centrally. Did you want the nav buttons on the actual side and not centered?
0

#47 User is offline   Neji 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 204
  • Joined: 26-February 09
  • Reputation: 20
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 13 March 2009 - 11:34 PM

I want the nav buttons to sit under the logo because I plan to have a search under the join now banner. Then I want the grey bar itself to reach to the end of the browser window.
0

#48 User is offline   Ben 

  • Web Designer Forum Admin
  • View gallery
  • Group: Root Admin
  • Posts: 2,840
  • Joined: 24-August 06
  • Reputation: 102
  • Gender:Male
  • Location:Essex, UK
  • Experience:Intermediate
  • Area of Expertise:Web Designer

  Posted 13 March 2009 - 11:40 PM

Hi,

Sorry for the questions, but i've been on your website and what you are asking to happen, already seems to be working... See my screenshot attached

Green arrows indicated the 100% width of grey bar and Red arrow indicates the nav is sitting under the logo...

Am I missing something here?

Attached File  eden.jpg (21.41K)
Number of downloads: 6
0

#49 User is offline   Neji 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 204
  • Joined: 26-February 09
  • Reputation: 20
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 14 March 2009 - 12:09 AM

Don't worry about all the questions, I appreciate the help.

If you look at my CSS, I'm actually using a background image in the body tag. So, the bar you see is actually part of the sites background not part of the navbar. I'm sure there must be a better way?

The problem is, in IE the background/nav bar don't match so I want to beable to position the navbar and I can't do that if it is part of the background image.
0

#50 User is offline   Neji 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 204
  • Joined: 26-February 09
  • Reputation: 20
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 14 March 2009 - 06:16 PM

I've uploaded my current code, I've been trying to do this but still cannot get it right.

Clicky

I want it took look like the image posted above by Ben.

Thanks in advance for any help.
0

#51 User is offline   Showtime 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 13
  • Joined: 14-March 09
  • Reputation: 0
  • Experience:Beginner
  • Area of Expertise:Designer

Posted 16 March 2009 - 01:46 AM

EDIT: nevermind, solved own problem.

Very useful tutorial!
0

#52 User is offline   Chris1993 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 21-June 09
  • Reputation: 0
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 07 July 2009 - 09:01 AM

Hi, thanks for the great tutorial, its taught me a lot about CSS (or rather more or less everything I know about CSS :p) however I still can't get one thing to work...drop downs. I know its not intended to be there originally but I've spent several days now trying to add them to it with little success, can anyone give some pointers for adding them?

Many thanks once more.
0

#53 User is offline   Chris1993 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 21-June 09
  • Reputation: 0
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 07 July 2009 - 10:32 AM

Doesn't matter any more, I've finally worked out a way to do it, even if inefficiently. :) :) :)
0

#54 User is offline   liz 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 17-November 09
  • Reputation: 0

Posted 17 November 2009 - 07:01 AM

View Postkrakatoa, on 28 November 2008 - 11:38 AM, said:

Here's an easy method to create CSS rollovers (in this example b1.gif and b2.gif are the two button states):

<style>
img.nohover {border:0}
img.hover {border:0;display:none}
A:hover img.hover {display:inline}
A:hover img.nohover {display:none}
</style>
<A HREF="#">
<img src="b1.gif" class="nohover">
<img src="b2.gif" class="hover">
</A>


0

#55 User is offline   liz 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 17-November 09
  • Reputation: 0

Posted 17 November 2009 - 07:34 AM

Hi, I found your tutorial very helpful and it works great. Have you used this with any method of showing the current page you are on by having it display in the rollover state when you are on that page? I tried to use your rollover with the javascript method on this page http://www.richnetap...urrent_page_in/ to create a current page marker but couldn't get it to work. Maybe it's because I'm not using a list and don't know how to call it up correctly.

Thanks,
L
0

#56 User is offline   bisto 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 18-March 10
  • Reputation: 0
  • Gender:Male
  • Location:London, UK
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

Posted 18 March 2010 - 02:51 PM

Hi Ben,

Well done on the tutorial!
This was just what i was looking for and i will be trying it out, soon.

Thanks alot!
0

#57 User is offline   jamezb3 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 30-March 10
  • Reputation: 0

Posted 30 March 2010 - 11:55 PM

Thanks heaps for the tut, really easy to follow and works a treat :)
0

#58 User is offline   KellyB 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-April 10
  • Reputation: 0
  • Gender:Female
  • Location:Dagenham, Essex UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 15 April 2010 - 10:48 AM

Hi great tutorial.
Not sure if you can help but after adding this navigation menu to my test website all appears fine except in internet explorer 7. In ie7 the menu is pushed to the right and is hidden until you rollover the menu when the hover image shows. Can anyone tell me what I am missing please? Site is http://www.norkey.com/pov/test and css is located here http://norkey.com/po.../css/layout.css

I'm a beginner to css so not sure what I've done wrong.

Thanks
Kelly
0

#59 User is offline   LenP 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 17-June 11
  • Reputation: 0

Posted 17 June 2011 - 04:22 PM

nice tutorial, very helpful!

Try as I might however, I cannot get the 'hover' to change image position. It stays on the top half of the image.

Basically followed your code but added a 5th button and changed some names around.

Any thoughts?

TIA,
Len
0

#60 User is offline   cibgraphics 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 779
  • Joined: 11-September 08
  • Reputation: 75
  • Gender:Male
  • Location:Utah, USA
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 17 June 2011 - 06:33 PM

Just use a CSS sprite. Less requests, controllable from the CSS instead of inline HTML, and sometimes smaller file size.

This seems more of like a poor hack when you don't know how to do it correctly.
0

#61 User is offline   nauset 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 06-December 11
  • Reputation: 0

Posted 06 December 2011 - 03:44 AM

Hello forum :)

Thanks for the tutorial, it's very useful. my question is about nav buttons with different widths- I saw that it was mentioned but I'm a beginner in CSS and I would love a visual explanation so I can learn. i'm using 6 buttons, the first three are around the same width as the default in the tutorial. the next two are almost twice as big, and i'm struggling.

any help would be appreciated. thanks. i've uploaded my test page, as i don't want to live update my portfolio site until i know it's perfect.

http://nausetee.net/...r-tutorial.html

This post has been edited by nauset: 06 December 2011 - 03:53 AM

0

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

13 User(s) are reading this topic
0 members, 13 guests, 0 anonymous users