Jump to content

Defining A:Link and A:Hover values in-line?


DaveLinger

Recommended Posts

What I'm trying to do is have a link ("a" tag) which is just an image, 150x150. If you click it, it goes somewhere. On hover over, it should change to a different 150x150 image. Only problem is, due to the php code determining the bg image url, I have to do it inline.

 

<div style="width:150px; height:150px; a:link {background-image:url(frozen/thumbs/1_f.jpg);} a:hover {background-image:url(frozen/thumbs/1_c.jpg);}"><a href="frozen/1.jpg""> </a></div>

 

This code does not show the image.

Link to comment
Share on other sites

are your image paths stored in a database that relates the link/hover thumbnail to each other and to the image they lead to?  If they are, then you can dynamically generate the css info:

 

//put this php code within your css in the head section
//run your query, selecting all rows from the images table.
//then while looping through the array
echo "#image" .$row['id']. " {width: " .$row['width']. "; height: " .$row['height'].
"background: url(" .$row['thumbnail_off_path']. ");}";
echo "#image" .$row['id]. ":hover {background: url(".$row['thumbnail_on_path'].");}";

 

Then in the body where you want the links to show up

//run your query to select all rows of the images table
//while looping through the array
echo '<a id="' .$row['id'].'" href="'.$row['path_to_full_image'].'"></a>';

 

If your not using a database to dynamically generate your links, I'm not sure how you'd do it as there's no way really to relate the background images to each other and to the main image.  But if you want to set up a table for it you'd just need rows for id, link_off_path, link_on_path and target_path

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.