WordPress Header Image Invisible due to Zero Height after Update to 6.1

After my customer’s web hoster updated WordPress from 6.0.2 to 6.1, the responsive hero header images were not visible anymore. Comparing the HTML source code and CSS styles, we found the problem and the solution.

After I posted the problem on StackOv…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Ingo Steinke

After my customer's web hoster updated WordPress from 6.0.2 to 6.1, the responsive hero header images were not visible anymore. Comparing the HTML source code and CSS styles, we found the problem and the solution.

After I posted the problem on StackOverflow, unsurprisingly, apart from the obvious and correct suggestion to ask it on wordpress.stackexchange.com instead, instead of answers it attracted downvotes without any further comments, so I realized DEV, as a more helpful and inclusive community, might be a better place to share our insights.

"The Problem: Missing Header Images"

Our hero header images were no longer visible in a full-site-editing enabled block theme (originally based on Block Base) as their computed height changed zero pixels.

Changing the style from height: 100% to height: auto made the images appear again, but only partially.

When comparing the markup, class names, and applied styles, I first failed to see the difference, apart from the fact that height: 100% now computes to zero height and the image position seems to have changed too.

A new Container Class: is-layout-constrained

There is a new container class, .is-layout-constrained which should not affect the image height as I understood.

A new relative Image Wrapper

As the image has position: absolute, this might be due to a change to a parent container. And it is!

Our next positioned parent is the wrapping <figure> element figure.wp-block-post-featured-image around the actual image. This figure element defaults to position: relative in WordPress 6.1, so it serves as a new nearest positioned ancestor (as described in MDN's Absolute positioning article).

The following CSS is present only after updating to WordPress 6.1:

.wp-block-post-featured-image {
    /* position: relative; */
}

This breaks images set to cover as a hero image like this:

__computed_styles {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

A possible solution is to revert the image wrapper to the previous state by explicitly setting the position back to static. I added both the parent header and the actual figure element just to make sure to override the default style by giving the new rule a greater specificity than the original one:

header figure.wp-block-post-featured-image {
  position: static;
}


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Ingo Steinke


Print Share Comment Cite Upload Translate Updates
APA

Ingo Steinke | Sciencx (2022-11-14T07:30:06+00:00) WordPress Header Image Invisible due to Zero Height after Update to 6.1. Retrieved from https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/

MLA
" » WordPress Header Image Invisible due to Zero Height after Update to 6.1." Ingo Steinke | Sciencx - Monday November 14, 2022, https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/
HARVARD
Ingo Steinke | Sciencx Monday November 14, 2022 » WordPress Header Image Invisible due to Zero Height after Update to 6.1., viewed ,<https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/>
VANCOUVER
Ingo Steinke | Sciencx - » WordPress Header Image Invisible due to Zero Height after Update to 6.1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/
CHICAGO
" » WordPress Header Image Invisible due to Zero Height after Update to 6.1." Ingo Steinke | Sciencx - Accessed . https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/
IEEE
" » WordPress Header Image Invisible due to Zero Height after Update to 6.1." Ingo Steinke | Sciencx [Online]. Available: https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/. [Accessed: ]
rf:citation
» WordPress Header Image Invisible due to Zero Height after Update to 6.1 | Ingo Steinke | Sciencx | https://www.scien.cx/2022/11/14/wordpress-header-image-invisible-due-to-zero-height-after-update-to-6-1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.