How do I leave the opacity of a dark image and display the figcaption text on Hover?

Asked

Viewed 3,841 times

4

Hello, I am trying to leave the image dark and appear the text when I hover over. Can anyone help me?

<div class="efeito">
    <figure>
        <a href="#" target="_blank"><img src="comunica.jpg" ></a>
        <figcaption><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit</span></figcaption>
    </figure>
</div>

CSS:

.efeito{
    -webkit-filter:opacity(100%);
}
.efeito figcaption{
    color: #000;
    position: absolute;
    opacity: 0;
}
.efeito figcaption:hover{
    opacity: 1;
}
.efeito img:hover{
    -webkit-filter:opacity(0%);
    transition: 1s;
}

2 answers

2


.efeito {
  opacity: 1;
  position: relative;
}
.efeito figure .box-black {
  position: absolute;
  width: 100%;
  height: 0%;
  left: 0;
  bottom: 0;
  opacity: 0;
  z-index: 1;
  background-color: #000;
  transition: all 0.5s ease-in;
}
.efeito figure {
  position: relative;
  width: 350px;
  height: 150px;
  vertical-align: middle;
}
.efeito figcaption {
  color: #000;
  position: absolute;
  opacity: 0;
  left: 0;
  bottom: 0;
  color: #FFF;
  font-size: 20px;
  text-align: center;
  display: block;
  margin: auto;
  transform: translateY(0%);
  transition: all 0.5s ease-in .5s;
  z-index: 2;
  width: 100%;
}
.efeito:hover figure .box-black {
  opacity: 0.5;
  height: 100%;
}
.efeito:hover figure figcaption {
  opacity: 1;
  bottom: 30px;
}
<div class="efeito">
  <figure>
    <div class="box-black"></div>
    <a href="#" target="_blank">
      <img src="http://placehold.it/350x150">
    </a>
    <figcaption>
      <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>
    </figcaption>
  </figure>
</div>

  • 1

    It worked! That’s what I wanted!

0

The problem is that the class efeito encompasses the other elements, which in turn inherit the characteristics of the parent element:

.efeito{
    -webkit-filter:opacity(100%);
}
.efeito figcaption{
    color: #000;
    position: absolute;
    opacity: 0;
}
.efeito figcaption:hover{
    opacity: 1;
}
.efeito img:hover{
    -webkit-filter:opacity(0%);
    transition: 1s;
}
<div>
    <figure>
        <a href="#" target="_blank"  class="efeito"><img src="http://www.rodandopelomundo.com/wp-content/uploads/2015/12/moscow-e1449164201996.jpg" >
       </a>
       <figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit                </figcaption>
    </figure>
</div>

  • I wanted the fade of the image to be dark and the text to appear together at the Hover

  • Um... got it wrong...heuheuheu

Browser other questions tagged

You are not signed in. Login or sign up in order to post.