1

I'm kicking myself here as I've done this plenty of times before, but for some reason my code is not working and I can't workout why. I've been staring at it for a while now so that probably doesn't help. Anyway I'm trying to do a CSS on hover. So when you hover over a div with it displays another div.

HTML

<div class="pressListItem">
   <img src="" width="" height="">
   <h3>July 2013</h3>
</div>
<div class="pressItemHover">
   <p>This is come more content, lalala here is a little snippet</p>
   <span></span>
   <span>Read more</span>
</div>

CSS

I'm using the opacity transition as I want it fade in.

.pressItemHover{
    opacity: 0;
    transition: opacity 0.5s linear 0s;
    visibility: hidden; 
}

.pressListItem:hover .pressItemHover{
    opacity: 1;
    visibility: visible;
}

.pressListItem{
    width: 200px;
    float: left;
    height: 200px;
    margin-right:12px;
    text-align: center;
    border: solid 1px #e4e4e4;      
}

If anyone could point out what I'm doing wrong it would be much appreciated!

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
JDavies
  • 2,730
  • 7
  • 34
  • 54

2 Answers2

4

Change the selector to:

.pressListItem:hover + .pressItemHover {
    opacity: 1;
    visibility: visible;
}

jsFiddle example

.pressListItem:hover .pressItemHover looks for an element with the class pressItemHover that is a descendant of pressListItem when in reality it's a sibling, in which case you want to use the adjacent sibling selector +.

j08691
  • 204,283
  • 31
  • 260
  • 272
0

In your HTML .pressListItem and .pressItemHover are siblings. In your CSS you're defining styles to a div which is a child of .pressListItem. You need to change HTML to this

<div class="pressListItem">
    <img src="" width="" height="">
    <h3>July 2013</h3>

    <div class="pressItemHover">
        <p>This is come more content, lalala here is a little snippet</p>
        <span></span>
        <span>Read more</span>
    </div>
</div>

or if you don't wan't to restructure your DOM you can just change this part of CSS

.pressListItem:hover + .pressItemHover {
matewka
  • 9,912
  • 2
  • 32
  • 43