CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 13th, 2004, 07:05 PM
StaticAge StaticAge is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 StaticAge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
CSS image/text rollovers- how?

Using either CSS, or JavaScript, or a combination of both; is it possible to do this without using frames?:

image1 and image2 are laid out horizontally across the top of the page.

When the mouse hovers over image1, a formatted body of text (lets call it "text1") is displayed beneath the layout of images. As the mouse leaves image1, the text disappears.

When the mouse hovers overs over image2, a different body of text ("text2") appears in the same area where text1 was displayed. It also disappears as the mouse leaves.

I am probably very obviously a newbie. I have read examples that show how to do similar things with frames, and I can script simple image rollovers, but I am a little lost here, so even if this is too basic a question, if you can point me in the right direction to learn how, I would appreciate it much. Thanks in advance for any help or suggestions!

Reply With Quote
  #2  
Old February 13th, 2004, 07:39 PM
Detrifuse's Avatar
Detrifuse Detrifuse is offline
Bites when cornered
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Back from Iraq!
Posts: 109 Detrifuse User rank is Corporal (100 - 500 Reputation Level)Detrifuse User rank is Corporal (100 - 500 Reputation Level)Detrifuse User rank is Corporal (100 - 500 Reputation Level)Detrifuse User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Writing a script to do that is fairly simple.
The method I would use is to contain the formatted text in a div and change it's display properties via javascript:
Code:
(untested)
<html>
<head><title>Test</title>
<style>
#i1 /* formatting for image 1 text */
{
  display: none;
  font: 10pt "Tahoma";
}

#i2 /* formatting for image 2 text */
{
  display: none;
  font: 10pt "Tahoma";
}

</style>
<script>
function show_chunk(id)
{
  var chunk = document.getElementById(id);
  chunk.style.display = "block";
}

function hide_chunk(id)
{
  var chunk = document.getElementById(id);
  chunk.style.display = "none";
}
</script>
</head>
<body>
<img src="image1.gif" onmouseover="show_chunk('i1');" onmouseout="hide_chunk('i1');">
<img src="image2.gif" onmouseover="show_chunk('i2');" onmouseout="hide_chunk('i2');">

<div id="i1">
This is the text for our first image.  It cannot be seen until the image is hovered over.
</div>

<div id="i2">
This is the text for our second image.  It cannot be seen until the image is hovered over.
</div>
...
rest of html

A word of warning: if you don't preserve a spot for the text to display into, you will experience "reflow," or dynamic redrawing of your page (ie when you hover over the image, the text that shows will "push" the rest of the page down). There are two ways to prevent this: you can set the display property (ie chunk.display) to hidden, or you can save it a spot by using CSS. I prefer using CSS because I feel it gives me more control than letting the browser decide.


HTH
__________________
Obstruct the doors, cause delays, be dangerous.

Reply With Quote
  #3  
Old February 13th, 2004, 08:19 PM
StaticAge StaticAge is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 StaticAge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks so much. That is exactly the kind of thing I was looking for.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > CSS image/text rollovers- how?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway