Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

css show several items on hover

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
I agreed to build a charity website, all is good and complete apart from an area on the homepage where they intend to show a graphic, hover over an area and that part changes, but also some text appears and a line changes colour to indicate it has been chosen.

I have attached an image showing what I mean. The first item is the default state, hover over the left circle and the circle changes slightly, a line appears, the dotted line changes colour and some text is displayed.

My question is how would I achieve this in css?

Thanks for any help
 
 http://files.engineering.com/getfile.aspx?folder=831df04a-8993-4e60-aa5a-41b476577b29&file=homepage-chooser.png
If you have this image as uploaded to engineering.com you can use it as a links background-image, set background-repeat: no-repeat; and set the background-position-y triggered by hovering the circles areas of the following <map> section:

Code:
<map name="sitemap">
  <area shape="circle" coords="x1,y1,r" href="page1.htm" onmouseenter="javascript:call function to set background-position-y" onmouseleave="javascript:call function to reset background-position-y">
  <area shape="circle" coords="x2,y2,r" href="page2.htm" onmouseenter="javascript:call function to set background-position-y" onmouseleave="javascript:call function to reset background-position-y">
  <area shape="circle" coords="x3,y3,r" href="page3.htm" onmouseenter="javascript:call function to set background-position-y" onmouseleave="javascript:call function to reset background-position-y">
  <area shape="circle" coords="x3,y3,r" href="page4.htm" onmouseenter="javascript:call function to set background-position-y" onmouseleave="javascript:call function to reset background-position-y">
</map>

You have to specify the coordinates of the circles and their approximate radius and define a javascript function to set the background-position-y to display part of the image for the corresponding circle or for no active circle.

Bye, Olaf.
 
Depending on how that display is constructed (HTML, CSS) would be how to approach it.

Assuming the circles, the dotted lines, the text and the house are all a single image, but you have separate images for each button selection state you can simply change the image on hover of each area. You don't even need to muck around with background positions if all of them are the same size, you simply swap it, and the line and and text and hover effect appear from the image.

If All states are contained within the image i.e exactly as your uploaded image, then yes you would need to be moving the image around so the specific state is shown. Make sure the div that contains this image has overflow set to hidden in the CSS. If you do take this approach, make sure your image is well optimized if its going to be very large physically.

Personally to cut down on load times of a very large image I'd probably make 5 different optimized images and swap them.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I couldn't figure out how to achieve this using just css so for speed for now I have used jquery to add a class that updates the background position. The whole image is just 65kb so this will work fine for now until I have more time to revisit it later.

Thanks for the suggestions
 
No real way to achieve it using only CSS. You do need Js in some form to alter the CSS.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top