I've created a simple example for you.
I did the following
Changed style=
to class=
style is only used for inline styles.
I added the class .block
to the divs so you can target them together
I moved the img
to the first block so you can set it relative to that container (also why I added position: relative
to the .block
class
After that I absolutly position the image relative to it's parent. Because i know the image is going to be 150px height I can give it bottom: -75px
to place it halfway.
Then I've added left: 50%; transform: translatex(-50%);
to position in the abosolute middle of the container.
z-index: 2;
is so it comes behind the second .block
.block {
width: 100%;
height: 300px;
position: relative;
}
img {
position: absolute;
bottom: -75px;
z-index: 2;
left: 50%;
transform: translatex(-50%);
}
.bg-gray{
background-color:gray;
}
.bg-white{
background-color:white;
}
<div class='block bg-gray'>
<img src='https://via.placeholder.com/150'>
</div>
<div class='block bg-white'>
</div>