0

I am following a tutorial for hover effect on images where text pops up and background turns dark. Tutorial here.

I am having a small problem with the hover effect, when mouse hovers over the image, I want the image to go dark and the entire image is covered, when I set the ul.img-list li to height 100% it only takes up 100% of the text, I can set the height to the height of the image, but when the height changes based on the window size, it won't cover properly. Am I missing something?

image example

HTML:

<div class="column large-6">
   <ul class="img-list">
     <li>
       <a href="#">
         <img src="https://www.ricoh.com/r_dc/r/r8/img/sample_08.jpg" />
         <span class="text-content">
           <span>Hello@!</span>
        </span>
      </a>
    </li>
 </ul>

CSS:

ul.img-list {
  list-style-type: none;
  margin: 0;
  padding: 0;
  text-align: center;
}
ul.img-list li {
  display: inline-block;
  height: 100%;
  margin: 0 1em 1em 0;
  position: relative;
  width: 100%;
}
span.text-content {
  background: rgba(0,0,0,0.5);
  color: white;
  cursor: pointer;
  display: table;
  height: 150px;
  left: 0;
  position: absolute;
  top: 0;
  width: 150px;
}

span.text-content span {
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}

span.text-content {
  background: rgba(0,0,0,0.5);
  color: white;
  cursor: pointer;
  display: table;
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  width: 150px;
  opacity: 0;
  -webkit-transition: opacity 500ms;
  -moz-transition: opacity 500ms;
  -o-transition: opacity 500ms;
  transition: opacity 500ms;
}

Here is my jsfiddle - http://jsfiddle.net/f32kn4h5/

TJXStyles
  • 267
  • 4
  • 15
  • 1
    This question is relevant, maybe it will help.. http://stackoverflow.com/questions/18322548/black-transparent-overlay-on-image-hover-with-only-css – Josh Crozier Apr 01 '15 at 15:58
  • This is very helpful, added to favourite, thank you! – TJXStyles Apr 01 '15 at 16:03
  • the fiddle seems to work fine for me. Nevermind no it doesn't – Steve Apr 01 '15 at 16:09
  • @JoshCrozier I really like your solution with text on hover... What if I wanted to combine a font awesome font with text? – TJXStyles Apr 01 '15 at 16:35
  • @TJXStyles I guess you would have to ditch the pseudo-element caption and actually insert a element for the caption.. http://jsfiddle.net/6pem20px/ – Josh Crozier Apr 01 '15 at 16:42
  • did my answer help solve your issue? you can mark it as accepted if it did – duxfox-- Apr 01 '15 at 19:52
  • @AbdulAhmad It worked in Firefox but not in Chrome or Safari, I upvoted anyway! – TJXStyles Apr 02 '15 at 20:22
  • @TJXStyles I'm using safari and its working for me, did you check the fiddle? – duxfox-- Apr 02 '15 at 20:30
  • JSFiddle works perfectly in the browsers I tested but when I implemented the code into my code, it didn't show up properly, I will try again and let you know my findings. Thanks! – TJXStyles Apr 03 '15 at 18:00

1 Answers1

1

I think part of your problem after looking at your fiddle is that none of your parent divs have a height property set to something static. If you try changing the span styling to say, 300px, you will see it change:

span.text-content {
  height: 300px;
}

alternatively, set every parent of that text span's height to 100% or something, but height must be present for every parent:

<div class="column large-6"> //set to 100% or something
   <ul class="img-list">  //set to 100% or something
     <li>  //set to 100% or something
       <a href="#">
         <img src="https://www.ricoh.com/r_dc/r/r8/img/sample_08.jpg" />
         <span class="text-content">
           <span>Hello@!</span>
        </span>
      </a>
    </li>
 </ul>

this should make it work, here's an update to your fiddle: http://jsfiddle.net/f32kn4h5/3/

duxfox--
  • 9,097
  • 15
  • 55
  • 116