Make an image go dark and text appear when hovered over

3.6k views Asked by At

I am trying to create an effect when I hover over an image, the image goes dark (so the opacity goes down) and text appears. The effects is basically this towards the bottom: http://www.ohmy.io/ . I can do one of the effects on their own, but doing both together they are almost fighting each other and goes dark for half a second then back light.

.vividworknav {
  width: 33.333%;
  height: auto;
  float: left;
  padding: 0;
  -webkit-transition: opacity 0.5s ease-out;
  -moz-transition: opacity 0.5s ease-out;
  -o-transition: opacity 0.5s ease-out;
  transition: opacity 0.5s ease-out;
}
.vividworknav:hover .work-text-content {
  visibility: visible;
  opacity: 1.0;
}
.vividworknav:hover {
  opacity: 0.3;
}
.work-text-content {
  width: 33.333%;
  height: auto;
  visibility: hidden;
  z-index: 100;
  position: absolute;
  color: white;
  left: 0%;
  top: 25%;
  font-size: 24px;
  text-align: center;
  -webkit-transition: visibility opacity 2.0Ms;
}
<div class="vividworknav">
  <img src="http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />
  <div class="work-text-content">
    <p>VIVID VAPOURS</p>
  </div>
</div>

2

There are 2 answers

0
kaytcat On BEST ANSWER

I added a black background to the parent element vividworknav, then I just set the opacity of the image and text on hover and then it seems to work fine.

    .vividworknav {
      width: 33.333%;
      height: auto;
      float: left;
      padding: 0;
      position: relative;
      background-color: black;
    }

    .vividworknav:hover img {
      opacity: 0.3;
    }

    .vividworknav:hover .work-text-content {
      opacity: 1; 
    }

    .vividworknav img {
      padding: 0;
      width: 100%;
      display: block;
      opacity: 1;
    }

    .vividworknav img,
    .work-text-content {
      -webkit-transition: opacity 0.5s ease-out;
      -moz-transition: opacity 0.5s ease-out;
      -o-transition: opacity 0.5s ease-out;
      transition: opacity 0.5s ease-out;
    }

    .work-text-content {
      position: absolute;
      color: white;
      left: 0;
      top: 25%;
      right: 0;
      bottom: 0;
      font-size: 24px;
      text-align: center;
      opacity: 0;
    }
<div class="vividworknav">
  <img src="http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />
  <div class="work-text-content">
    <p>VIVID VAPOURS</p>
  </div>
</div>

8
Dreamweaver On
        .vividworknav{
            width:33.333%;
            height:200px;
            float:left;
            padding:0;
            -webkit-transition: opacity 0.5s ease-out;
            -moz-transition: opacity 0.5s ease-out;
            -o-transition: opacity 0.5s ease-out;
            transition: opacity 0.5s ease-out;
            background-image: url("http://www.gettyimages.co.uk/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg");
        }

        .vividworknav:hover .work-text-content{
            opacity: 1.0;
        }

        .work-text-content{
            background-color: rgba(0,0,0,0.8);
            width:33.333%;
            height:100%;
            opacity: 0;
            z-index:100;
            position:absolute;    
            color:white;
            left:0%;
            font-size:24px;
            text-align:center;
           -webkit-transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000); 
           -moz-transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000); 
           -o-transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000); 
            transition: all 500ms cubic-bezier(0.420, 0.000, 0.580, 1.000); /* ease-in-out */
       -webkit-transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000); 
       -moz-transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000); 
  -o-transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000);   
  transition-timing-function: cubic-bezier(0.420, 0.000, 0.580, 1.000); /* ease-in-out */
        }