Issue
I have a block on my website that I want to have a background image with an overlay on top to make it less visible, and then some content on top of that. I want the height of the div/image/content to be at least 100vh on large screens, but on smaller screens it needs to be higher since the content covers more than 100vh.
I tried the following but the text overflows the div and the image is only at 100vh still.
.homepage-top-image-wrapper {
position: relative;
width: 100%;
min-height: 100vh;
}
.homepage-top-image-wrapper .image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
}
.homepage-top-image-wrapper .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.home-content-block {
max-width: 1100px;
color: blue;
}
<div class="homepage-top-image-wrapper">
<div class="image" style="background-image: url('https://t4.ftcdn.net/jpg/03/17/72/47/360_F_317724775_qHtWjnT8YbRdFNIuq5PWsSYypRhOmalS.jpg');"></div>
<div class="overlay">
<div class="home-content-block">
<div class="home-content-subtitle" style="font-size:5rem">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
</div>
</div>
Solution
I think the problem is that you are using your content inside overlay
that is absolutely positioned so the height of your content won't be the height of your main container homepage-top-image-wrapper
.
you can change your html structure like this:
<div class="homepage-top-image-wrapper">
<img class="image" src="https://t4.ftcdn.net/jpg/03/17/72/47/360_F_317724775_qHtWjnT8YbRdFNIuq5PWsSYypRhOmalS.jpg" alt="">
<div class="overlay">
</div>
<div class="home-content-block">
<div class="home-content-subtitle" style="font-size:5rem">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
now your container will resize by the content.
you have to change your css accordingly to achieve same thing as before:
.homepage-top-image-wrapper {
position: relative;
width: 100%;
min-height: 100vh;
}
.homepage-top-image-wrapper .image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -10;
}
.homepage-top-image-wrapper .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
background-color: #00000080;
}
.home-content-block {
max-width: 1100px;
color: blue;
}
Answered By - ali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.