Click to See Complete Forum and Search --> : CSS image in span linking problem


justa messenger
06-05-2009, 02:30 PM
Hi, first of all i'm a bit new to this, but Compleet noob. pls be kind :)

Ok, so my issue is i have a type of image gallery made with spans.
I have the span tags enclosed by the <a href> tag. Spans are floating.
The reason for this is that I want to have the border change colors on hover,
wherever the pointer might be located in the span.

It works great in firefox and IE8, but i just discovered this morning, much to my dismay,
that it doesn't work in IE7 or below. of course it was the person i'm making the web
page for that pointed this out, go figure. The problem is that eventhough IE shows
that it is a link, when clicking on the image, nothing happens. text works find,
the area around image and text works fine, just not the image.

I tried searching google for a couple hours and could not find a fix that didn't involve
javascript. I'm trying to avoid JS as much as possible, and so far all has gone well.
Ok down to the nitty gritty.

I stripped down the html so that it just shows one of the spans, so if you drop the code
into notepad and save as htm you can play with it. css link is complete to my hosted css file.

honestly im not sure why im using that doc-type, i don't completely unerstand the mechanics,
i just thought for no sound reason at all that it would be better than html doc type.
xhtml 1.0 validates and css validates as 2.1.


<?xml version="1.1" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Bella Luna Gifts for the Soul - Wands</title>
<link rel="stylesheet" type="text/css" media="screen" href="http://www.bellalunagifts.net/main.css" />
<!--[if IE]>
<style type="text/css" media="screen">
body {
behavior: url(csshover.htc);
font-size: 100%;}
#menu ul {text-align:left;}
#menu ul li {float: left; width: 100%;}
#menu ul li a {height: 1%;}
#menu a, #menu h2 {
font: bold 12px/16px arial, "lucida console", sans-serif; padding: 3px 2px;}
</style>
<![endif]-->
</head>
<body>
<div id="page-container">

<div id="content">
<a href="http://www.bellalunagifts.net/rose_quartz_healing_wand.htm">
<span class="thumbnailleft"><img class="image" src="products/tn/rose_quartz_healing_wand.gif"
alt="Rose Quartz Healing Wand" width="150" /><br/><br/>Rose Quartz Healing Wand<br /></span></a>
</div>

</div>
</body>
</html>


If you just wanna glance at the css affecting the span and image, here it is.


.thumbnail {
float: left;
width: 150px;
height: 210px;
margin: 0 20px 15px 0px;
padding: 5px;
text-align: center;
border-style: ridge;
border-color: #3333FF;
text-decoration:none;
}

a {text-decoration: none;color: #000000;}
a:link .image {border-style: none;}
a:active .image {border-style: none;}
a:hover .thumbnailleft {
border-color: #00CCFF;}
a:hover .thumbnail {
border-color: #00CCFF;}
a:visited {text-decoration: none;color: #000000;}
a:visited .image {border-style: none;}


and i dont know why my docs are .htm instead of html.....long time ago i had a reason
that may or may not have been valid but i should probably change to .html, yeah?

well the link to the page im working on is
http://www.bellalunagifts.net/wands.htm

this is the last immediate piece of foundation code that i need to figure out to start rolling
out the rest of the website. this is the first time i've posted for help, i really do try to
figure out stuff on my own, but am ready to throw my head through the screen right now.

and hell, if i'm goin about this in a silly way, pls tell me. i always welcome criticism.

any help would be much much appreciated. i'm gonna keep trying to figure this out, but
i'm hoping that one of you already knows what i'm doing wrong. i know my css code is probably
redundant in places, but for now i'm just working on getting things to work.
thx in advance for any reply.

justa messenger
06-05-2009, 03:43 PM
I must be daft. cant see the link to edit my own thread even though i already did. meant to say im not a complete noob, heh.

peachskittle
06-05-2009, 03:52 PM
A few recommendations so that you can make it do what you want it to.

Remove the spans from your markup. Yes this does mean you'll have to find another home for all those styles under thumbnail, but that's not a huge problem.

Give your <a>s a width and height(I just stuck some in there, you can determine the exact dimensions you need). Give your <a>s that are being used here a specific class. In that class, give it its border and hover border. So


<a href="chakra_prism_wand.htm" class="someclassname">
<img class="image" src="products/tn/chakra_prism_wand.jpg" alt="Chakra Prism Wand" width="150" /><br /><br />Chakra Prism Wand<br />
</a>


and the css for the link


a.someclassname {text-decoration: none;color: #000000; width: 150px; height: 250px;}
a.someclassname { border: 2px ridge #3333FF; }
a.someclassname:hover { border-color: #00CCFF; }

justa messenger
06-05-2009, 05:42 PM
Ok not exactly what i was looking for, but it did help alot. and cleaned up my css a bit, thx. I switched to divs instead of spans, keeping the same .thumnail class.

the html:


<div class="thumbnail"><a href="chakra_amethyst_wand.htm"
class="links"><img class="image" src="products/tn/chakra_amethyst_wand.jpg"
alt="Chakra Amethyst Wand" width="150" /><br/><br/>Chakra Amethyst
Wand<br /></a></div>


and the css:


.thumbnail {
float: left;
width: 150px;
height: 210px;
margin: 0 20px 15px 0px;
padding: 5px;
text-align: center;
border-style: ridge;
border-color: #3333FF;
text-decoration:none;
}

.thumbnail:hover {border:ridge #00CCFF;}
a.links {text-decoration: none; color: #000000; width: 150px; height: 210px;}
a:link .image {border-style: none;}
a:active .image {border-style: none;}
a:visited .image {border-style: none;}


It looks exactly as i want it to still, good stuff. Just to clarify the effect im
looking for...hovering in the area surrounding the image and text changes the border color of the div, which is working correctly. clicking image and text links to the next page correctly. I was hoping to get the surrounding area around the text and image to link to the next page as well.

I think that's why you told me to include the {width: 150px; height: 210px;}
declaration in a.links?(formerly comeclassname). I kinda hacked the code that you supplied a bit. tried to make it work. either it wasn't exactly what i was looking for or i didn't completely understand it enough to implement it completely.

Well either way, I guess I'm just bein picky. I like to be able to make things work exactly like i want them to, heh. Mabey i'm still doin somethin wrong. But at least i can start rollin out the rest of the page now, thanks.

peachskittle
06-05-2009, 09:23 PM
I think what I got from the op was that you wanted an entire link box around the image thumbnail and its text link, where that entire box would be displayed as the link space and clicking anywhere on that link box would work, and you wanted a hover border around that box that will change color regardless of where you hover over in that link area (that you set dimensions for). Was that what you were looking for?

justa messenger
06-11-2009, 03:44 PM
Yeah sounds about right :)