0
I’m trying to apply an effect with Hover, but I’m not getting it. I am using bootstrap 4. I managed to accomplish what I want or almost that, the problem is that appears below and not on the image.
Follows the code:
.texto{
padding:20px;
font-family:Arial;
text-align:center;
color:white;
opacity:0;
transition: opacity .2s linear;
background-color:rgba(0,0,0,.7);
}
.imagem:hover .texto{
opacity:1;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>teste</title>
</head>
<body>
<!-- Grid row -->
<div class="row">
<!-- Grid column -->
<div class="col-md-12 d-flex justify-content-center mb-5">
<button type="button" class="btn btn-outline-black waves-effect filter" data-rel="all">Exibir todos</button>
<button type="button" class="btn btn-outline-black waves-effect filter" data-rel="1">Granitos</button>
<button type="button" class="btn btn-outline-black waves-effect filter" data-rel="2">Quartzo</button>
<button type="button" class="btn btn-outline-black waves-effect filter" data-rel="3">Mármores importados</button>
<button type="button" class="btn btn-outline-black waves-effect filter" data-rel="4">Superfície artificiais</button>
</div>
<!-- Grid column -->
</div>
<!-- Grid row -->
<!-- Grid row -->
<div class="gallery" id="gallery">
<!-- Grid column -->
<div class="mb-3 pics animation all 2 imagem">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(73).jpg" alt="Card image cap">
<div class="texto"><h2>teste</h2></div>
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 1">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Vertical/mountain1.jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 1">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Vertical/mountain2.jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 2">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(35).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 2">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(18).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 1">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Vertical/mountain3.jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 3">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(18).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 3">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(35).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<div class="mb-3 pics animation all 3">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(73).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 4">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(18).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<!-- Grid column -->
<div class="mb-3 pics animation all 4">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(35).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
<div class="mb-3 pics animation all 4">
<img class="img-fluid" src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(73).jpg" alt="Card image cap">
</div>
<!-- Grid column -->
</div>
<!-- Grid row -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript">
$(function() {
var selectedClass = "";
$(".filter").click(function(){
selectedClass = $(this).attr("data-rel");
$("#gallery").fadeTo(100, 0.1);
$("#gallery div").not("."+selectedClass).fadeOut().removeClass('animation');
setTimeout(function() {
$("."+selectedClass).fadeIn().addClass('animation');
$("#gallery").fadeTo(300, 1);
}, 300);
});
});
</script>
</body>
</html>
I wanted the text to appear when positioning/hovering over the image, only, as I mentioned, the text appears below and not above.
P.S.: I did not resize the image to post here, considering that this is irrelevant to the understanding of the question.
give down vote without saying why?
– Lucas Inácio
Lucas, you just pasted all your code. Couldn’t you just tone down the noise and post only what matters? I already say that it seems to me that you did not know how to overlay text and image for lack of CSS knowledge. Take a look at how to do this with
position: absolute
andposition: relative
. PS: the downvote is not mine– fernandosavio
@fernandosavio agree with you, position in this case is the easiest to apply even. About downvote, I didn’t see much reason, sin for explaining more or putting code beyond enough to simulate the problem is better than not putting any code...
– hugocsl
@fernandosavio se o cara dizer o por qual motivo deu down vote, okay! I wasn’t born knowing, the guy who does this certainly can, but if someone gives a negative vote and doesn’t say where I’m going wrong (I don’t say in the code but in the questions), I won’t be able to correct, just this, criticism without feedback. Thanks for the comment, I’ll edit my question.
– Lucas Inácio
Lucas, it sucks getting downvote but it doesn’t shake you, sometimes it’s really unfair.
– fernandosavio