-5

I have an image on my home page (or index.html) and I want to be able to hover over the image then a black image fades on with a low opacity.

Example: http://wethepeoplebmx.de/hardgoods - if you go to hover over one of the images (or products), you can see the fade sort of thing I am trying to acomplish. I am fairly new at HTML and CSS, along with scripts and stuff like that. I'm assuming it's something to do with CSS, eg, hover, etc.

Thanks in advance

Josh Murray
  • 31
  • 1
  • 9

2 Answers2

1

You can do this with CSS3 animations and :hover.

.wrap {
  width: 100px;
  height: 100px;
  position: relative;
}
.effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
  background: none;
  /* First we need to help some browsers along for this to work.
     Just because a vendor prefix is there, doesn't mean it will
     work in a browser made by that vendor either, it's just for
     future-proofing purposes I guess. */
  -o-transition: .5s;
  -ms-transition: .5s;
  -moz-transition: .5s;
  -webkit-transition: .5s;
  /* ...and now for the proper property */
  transition: .5s;
}
.effect:hover {
  background: rgba(0, 0, 0, 0.4);
}
<div class="wrap">
  <img src="http://placehold.it/100x100">
  <div class="effect"></div>
</div>
Stewartside
  • 20,378
  • 12
  • 60
  • 81
0

I think you want something like this -

.wrap{position:relative;height: 100px;width: 120px;}
    .wrap img{width: 100%;;height: 100%;}
    .effect{background: rgba(0, 0, 0, .5);;position: absolute;height: 100%;width: 100%;;top:0;display: none;}
    .wrap:hover .effect{display: block;opacity:.4}
<div class="wrap">
    <img src="http://t0.gstatic.com/images?q=tbn:ANd9GcQiWGXo4U6CCvNItlDYFgEQz4d3T-YjLj13nqUZ-crpAr3qMPx-">
        <div class="effect">
            text
        </div>
    </div>
Mukul Kant
  • 7,074
  • 5
  • 38
  • 53