Dude you can use transform:translateX(-100%)
in the second image to put it over the first, do not need to use position
or float
Follow the example.
.wrap-elEx {
margin-bottom: 20px
}
.elEx {
width: 40px;
height: 40px
}
.elEx_first {
background-color: #8E44AD;
}
.elEx_last {
background-color: #23b14d
}
img.elEx_last {
transform: translateX(-95%);
}
Exemplo com IMG e transform: translateX de -95% para vc ver que ficou por cima mesmo... não tem float ou position
<div class="wrap-elEx">
<img src="https://i.imgur.com/KJHh65N.jpg" class="elEx elEx_first">
<img src="https://i.imgur.com/G6WP6yB.jpg" class="elEx elEx_last">
</div>
OBS 1: Important... the transform only plays one image on top of the other, but it still occupies the space where it should be, so if you put for example a text after the second image you will see that there will be an "empty" space between the superimposed images and the text...
OBS 2: I don’t know if it’s your case, but you can use one pseudo-elemento
to put one image on top of the other, without having to include another direct image in html
If you want to use it follow an option with pseudo-element. But as I said in the comment "or you use the content:url()
with the image already in the right size you need, or you will have to use the img as background-image
that ::after
. Besides you’ll need to put position:relative
in the div that will receive this pseudo element" Expand the code below to see the right code.
.wrap-elEx {
margin-bottom: 20px;
width: 40px;
height: 40px;
position: relative;
}
.wrap-elEx::after {
content: "";
background-image: url(https://i.imgur.com/G6WP6yB.jpg);
width: 40px;
height: 40px;
position: absolute;
top: 0;
left: 5px; /* o left tem que ser 0, só deixei 5 pra vc ver a img por baixo */
}
.elEx {
width: 40px;
height: 40px;
}
<div class="wrap-elEx">
<img src="https://i.imgur.com/KJHh65N.jpg" class="elEx ">
</div>
I thought it was because of the display block that the Divs have by default, but no, they behave in different ways even, I don’t know why, and now I’m curious rsrs. Ball show the question!
– Lucas de Carvalho
Ever thought of using one
pseudo-elemento
to do this?– hugocsl
have to be different pictures, so one
pseudo-elemento
wouldn’t work, I guess– Jefter Rocha
Jef works with different imgs yes, I will edit my answer and put an option of this type, but the pseudo element is not direct in the img tag but Sím in the div in which the img is inside!
– hugocsl
Face I even managed to do with pseudo-element, but either you use content:url() with the image already in the right size that you need, or you will have to use the img as background-image of this ::after. Besides that you will need to put position:relative in the div that will receive this pseudo element, so I think this option will not suit you... But if you want to tell me that I do an Edit in my answer with this option
– hugocsl
opa can send the answer, any help is welcome
– Jefter Rocha
OK young man edited the answer with what I managed to do using the pseudo-element...
– hugocsl