I want to create a responsive hero image, but I can't seem to center my picture element in a parent div. I already checked these posts:
Center image in div horizontally
Center align image within div horizontally
Center image element in parent div
As suggested in these other posts, I tried playing with margin: auto auto;
, with position
, setting min-width
to the parent div, but the image remains aligned to the far left.
Here's an example of what I'm trying to achieve
And here's my code (I've also created a jsfiddle: https://jsfiddle.net/wuy44t9p/1/):
<style type="text/css">
.profile-banner {
display: block;
height: 500px;
position: relative;
}
.profile-banner picture {
display: block;
margin: 0 auto;
position: absolute;
}
</style>
<div id="CPHBigBanner_pnlCoverPhoto">
<section class="profile-banner lazy">
<picture class="profile-herobanner lazy" data-was-processed="true">
<source type="image/webp" class="lazy" data-srcset="http://www.1001locaties.nl/images/tmp/41747_965_Owl.webp" srcset="/images/objphotos/covers/41747_965_Owl.webp" data-was-processed="true">
<img class="lazy loaded" data-src="http://www.1001locaties.nl/images/tmp/41747_965_Owl.png" alt="" src="/images/objphotos/covers/41747_965_Owl.png" data-was-processed="true">
</picture>
</section>
</div>