Adjust height of cover image to browser window
-
I’m trying to target the cover image block to adjust the height so it will always match the browser window regardless if you’re resizing the browser window or are on different machines. I want the bottom of the cover image to reach the bottom of the window and not extend beyond it or be too short. How can this be achieved?
I got this code out of ChatGPT but I can’t figure out the cover image block class name to replace the “.cover-image-class” with. There are too many options it seems. I tried “.wp-block-cover” but that didn’t do the trick. And maybe this code won’t do the trick at all.
/* Adjust cover image to fill the browser window height */
.cover-image-class {
height: 100vh; /* 100% of the viewport height */
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.cover-image-class img {
width: 100%;
height: auto; /* Adjust the height of the image proportionally */
object-fit: cover; /* Ensure the image covers the container */
}EDIT: I should add that changing the “Minimum height of cover” option to 100% of viewport height in the styles section when selecting the cover block in the editor doesn’t seem to be helping. The image extends beyond the browser window.
- You must be logged in to reply to this topic.