Following the idea of Antonio Alexandre, I made this small example using only CSS:
.image {
position: relative;
}
.image img {
position: absolute;
top: 0;
left: 0;
}
.image img:nth-child(1) {
z-index: 1;
transition: 1s;
}
.image img:nth-child(1):hover {
opacity: 0;
}
.image img:nth-child(2) {
z-index: 0;
}
<div class="image">
<img src="https://placeholdit.imgix.net/~text?txtsize=32&bg=55c1e7&txtclr=ffffff&txt=IMAGEM%201&w=200&h=200"><imgsrc="https://placeholdit.imgix.net/~text?txtsize=48&bg=55c1e7&txtclr=ffffff&txt=IMAGEM%202&w=200&h=200">
</div>
In short, within <div class="image">
, the two images are with position: absolute;
, occupying the same space and position.
With z-index
, set which image would overlap the other. The one above, takes the attribute transition: 1s;
.