Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-24-2012, 03:35 AM   PM User | #1
dinoandmaya
New to the CF scene

 
Join Date: Apr 2011
Location: Raleigh, NC
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
dinoandmaya is an unknown quantity at this point
Text Appears in Sidebar When Viewing Image on Hover

I'm currently working on a school project to build a simple web site using HTML and CSS only. I plan on using a simple gallery to showcase some photos and am using the same code (slightly modified) from this web site.

http://www.dynamicdrive.com/style/cs...image-gallery/

The changes I made are getting rid of the <br /> in the thumbnail area so they show in one row and the text and borders underneath the regular size images when the mouse hovers over the thumbnail.

However, I would like for text to appear in a sidebar (seperate block element) when the user hovers over the image. In other words, when the user hovers over one image, one set of text appears but when they hover over another image, a different set of text appears.

Is this possible using HTML and CSS only?
dinoandmaya is offline   Reply With Quote
Old 02-24-2012, 11:44 AM   PM User | #2
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
I am affraid not!

Css can alter the appearance of the hovered element and or it's child element.
It cannot alter the apperance nor content of outside elements

For this you will need a bit of javascript like:
Code:
onmouseover="document.getElementById('TextBox').innerHTML='Newtext' return true"
and
Code:
onmuseout="document.getElementById('TextBox').innerHTML='' return true"
added to the image tag.
Lerura is offline   Reply With Quote
Old 02-24-2012, 11:50 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
Yes it can be done. You need to work a little on this but it should do what you want.
From The CSS Guru (Drum roll) - http://meyerweb.com/eric/css/edge/popups/demo.html
sunfighter is offline   Reply With Quote
Old 02-25-2012, 08:56 AM   PM User | #4
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
Quote:
Originally Posted by sunfighter View Post
Yes it can be done. You need to work a little on this but it should do what you want.
From The CSS Guru (Drum roll) - http://meyerweb.com/eric/css/edge/popups/demo.html
This demo shows how you can do it, if the text is a child of a hovered item.
It is way to make text appear, but not the way OP wanted it to happen.

I will try to explain:
The OP way:
Code:
<div id="mainContainer">
<img src="My.first.picture">    <!--Trigger for My.first.Picture-->
<img src="My.second.picture">    <!--Trigger for My.second.Picture-->
<img src="My.third.picture">    <!--Trigger for My.third.Picture-->
<div class="text">You have hovered one of the picture</div>   <!--<Text for all the images-->
</div>
This cannot be done as the <div class="text"> is not a child of any of the triggering elements.

The Demo way:
Code:
<div id="mainContainer">
 <div class="pictureContainer">    <!--Trigger for My.Picture-->
  <img src="My.picture">                 
  <div class="text">You have hovered My.first.picture</div>    <!--Text for My.first.picture-->
 </div>
 <div class="pictureContainer">    <!--Trigger for My.second.Picture-->
  <img src="My.picture">                 
  <div class="text">You have hovered My.second.picture</div>    <!--Text for My.second.picture-->
 </div>
 <div class="pictureContainer">    <!--Trigger for My.third.Picture-->
  <img src="My.picture">                 
  <div class="text">You have hovered My.third.picture</div>    <!--Text for My.third.picture-->
 </div>
</div>
Now the trigger is no longer the images, but the .pictureContainer that contains both the image and it's related text.

As you can see, it requires a different, and larger, tree structure where you have 3 <div class="text">s instead of 1.

If OP wants to change it to the Demo way, make sure that each .pictureContainer exactly fits its contained image, and that the <div class="text">s are position:absolute

Maybe it will fulfil your requirements, though it is not what you asked for.
Lerura is offline   Reply With Quote
Old 02-25-2012, 03:08 PM   PM User | #5
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
I did say "You need to work a little on this". because I wasn't gonna. Since it depends on hover and not onclick, my mind tells me it can be done with css and html and if I was doing it, I'd give it a shot.
sunfighter is offline   Reply With Quote
Old 02-25-2012, 05:21 PM   PM User | #6
footballer27
New Coder

 
Join Date: Oct 2011
Posts: 85
Thanks: 13
Thanked 1 Time in 1 Post
footballer27 is an unknown quantity at this point
their both right. Although realistically, the only good way to do this is with javascript
footballer27 is offline   Reply With Quote
Old 02-26-2012, 12:11 AM   PM User | #7
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
Quote:
Originally Posted by sunfighter View Post
I did say "You need to work a little on this". because I wasn't gonna. Since it depends on hover and not onclick, my mind tells me it can be done with css and html and if I was doing it, I'd give it a shot.
Of course it can be done.
But to use the demo way, OP have to use a different document structure than originally planned.

Quote:
Originally Posted by footballer27 View Post
their both right. Although realistically, the only good way to do this is with javascript
You are oh so wrong.

If you can avoid using javascript, as you can do here, it is best to do it.
The CSS way will work even if the user have javascript disabled, (which many users have).

If there was anything in the document that required javascript, then you can just as well use javascript for this purpose.
But there isn't, and then there is no reason to make javascript:enabled a requirement
Lerura is offline   Reply With Quote
Reply

Bookmarks

Tags
appears, css, hover, html, text

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:53 PM.


Advertisement
Log in to turn off these ads.