-1

I have a bunch if <a> tags that have unique ids associated with them and children elements that are <img>. I would like to have the images hidden (display:none) by default and have them become visible when you hover over the <a> tag to which they belong. However, currently when I try this behavior using the #a-tag-id:hover selector in my css, the image does not become visible in the event of hovering.

Not really sure what I am doing wrong.

here is a fiddle with the same behavior.

http://jsfiddle.net/ebbnormal/bobmrud0/1/

Here is the original haml/css:

#map
  %a#saddleback_point
    =image_tag('saddleback_college.png', width:'300px')
  %a#citrus_point
    =image_tag('citrus_college.png', width:'300px')
  %a#sonrise_point
    =image_tag('sonrise.png', width:'300px')
  %a#vegas_point
    =image_tag('vegas.png', width:'300px')
  %a#tennessee_point
    =image_tag('tennessee.png', width:'300px')
  %a#chestnut_point
    =image_tag('chestnut.png', width:'300px')
  %a#saint_point
    =image_tag('saint.png', width:'300px')
  %a#boston_point
    =image_tag('boston.png', width:'300px')
  %a#fisher_point
    =image_tag('fisher.png', width:'300px')

#citrus_point img{
   top:360px;
  bottom:0px;
  left:240px;
   position:absolute;
   display:none; //TODO This is broken!
}
#citrus_point:hover img{
   display:block;
}
Thalatta
  • 4,510
  • 10
  • 48
  • 79
  • 1
    You know that `//` isn't valid CSS comment syntax right? And if you set something to display:none, how will hover get triggered if it's not being displayed? – j08691 Dec 23 '14 at 17:59
  • @j08691 Regrettably, I didn't know. Now I do. I updated the Fiddle. Thank you! – Thalatta Dec 23 '14 at 18:02

1 Answers1

1

To achieved this on hover your element need to be the child of the element that is hovered.

The element whoes styles are needed to be changed must be the descendent of the hovered element to work

Example

See the example below

 img{

   display:none; //TODO This is broken!
}
#my_a:hover img{
  display:block;
}
#my_a_withoutext{
   display:block;
   min-height:10px;
   min-width:10px;
   background:pink;
}
#my_a_withoutext:hover img{
  display:block;
}
 
<div id="unique_container">
    <a id="my_a">
        test
        <img src='http://0.tqn.com/y/altreligion/1/S/W/1/-/-/ouro-eliphas1947992_f248.jpg'/>
    </a>
   <a id="my_a_withoutext">
       
        <img src='http://0.tqn.com/y/altreligion/1/S/W/1/-/-/ouro-eliphas1947992_f248.jpg'/>
    </a>
    
</div>

In your case if no other elements are there in container and only the achor tag that you want to hover(that is child of the container) is visible than when you hover over it you are hovering parent. so you can generalize it for your specific condition this hack can work

#my_a img{

   display:none; 
}
#my_a:hover img{
   display:block;
}

#test{
 
 
}
#test:hover{
  display:normal;
}
#unique_container:hover img{
    display:block;
    
}
<div id="unique_container">
    <a id="my_a">
        <img src='http://0.tqn.com/y/altreligion/1/S/W/1/-/-/ouro-eliphas1947992_f248.jpg'/>
    </a>
    <a id="test">
        Hello Can you See Me?
    </a>
</div>
A.B
  • 20,110
  • 3
  • 37
  • 71