1

I need an image to appear when the overall container is hovered. I've tried accessing the class directly on the image and I've tried nesting the image in a div with no success. I have a feeling it is regarding the selectors ~, >, etc. but I cannot track this down for the life of me.

Here is my HTML Code:

<div class="container">
  <div class="info">
    <div class="sigma">
      <img src="http://www.wrightslaw.com/blog/wp-content/plugins/wpdiscuz/assets/img/plugin-icon/icon_info.png" align="right" style="margin: 7px 0;"  />
    </div>      
  </div>
  <div id="chart1" style=""></div>
</div>

Here is the CSS:

.container {
  width: 300px; 
  height: 300px; 
  background-color: #eceded; 
  position: relative;
}

.info {
  width: 290px; 
  height: 30px;
}

.sigma {
  display: none;
}

.container:hover~.sigma{
    display: block;
}

I also have a JSFiddle: http://jsfiddle.net/sthompson/eovn8o3p/2/

3 Answers 3

2

Remove the general sibling selector, ~

jsFiddle example

.sigma is a descendant (grandchild) of .container and ~ only applies to siblings. If for some reason you need to enforce the hierarchy, you could also use .container:hover > div.info > .sigma.

Sign up to request clarification or add additional context in comments.

1 Comment

better answer w/ explanation and fiddle :)
2

sigma is not a sibling of the container, so the ~ combinator in your selector is not appropriate. Neither is it an immediate child, so you should use just a simple selector instead:

.container:hover .sigma {

Updated fiddle

3 Comments

@AdamBuchananSmith And fiddle! Just not bold :o)
oh lol yeah you are right! I up-voted you both anyways (that's what counts)
better answer w/ explanation and fiddle :)
1

I think this is what you are looking for: http://jsfiddle.net/eovn8o3p/5/

.container:hover .sigma{
    display: block;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.