I have detected a problem with 100% width parallax background-image. I've to use fixed value of div height, because it's empty.
Problem is: empty space under background image when viewport is tight. Ask: how to create a responsive div height equals to background-image height.
My current searching and trying:
found: How to get div height to auto-adjust to background size?
trying two most popular methods with no effect,
prepare codepen: https://codepen.io/SeboFE/pen/xBVjzQ
// tried, but didn't work
// <div class="parallax">
// <img src="https://images.pexels.com/photos/574205/pexels-photo-574205.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260">
// </div>
// img{
// visibility: hidden;
// max-width: 100%;
// }
//second method didn;t work too
// .parallax{
// background-image: url("https://images.pexels.com/photos/574205/pexels-photo-574205.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260");
// background-attachment: fixed;
// background-repeat: no-repeat;
// background-size: 100% auto;
// padding-top: 60%;
// height: 0;
// }
html, body{
width: 100%;
margin: 0;
padding: 0;
}
.empty-space-20{
height: 20vh;
background-color: lime;
}
.parallax{
background-image: url("https://images.pexels.com/photos/574205/pexels-photo-574205.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260");
background-attachment: fixed;
background-repeat: no-repeat;
background-size: 100% auto;
height: 40vh;
}
.empty-space{
height: 1000px;
background-color: coral;
}
<div class="empty-space-20">some empty space</div>
<div class="parallax"></div>
<div class="empty-space">some empty space</div>