Hero Image in Block Theme spanning behind header into upper part of content area
-
Requirements
- MUST: Want to use a block theme (for easy styling and layout customizations).
- MUST: Hero image for pages (not blog-posts, there this would be covered with the featured image and a proper template)
- MUST: Individually decide per page whether is uses hero or not.
- MUST: Featured Image or Individual Image
- OPTIONALLY: Video which loops.
- MUST: Hero content spans
a) from viewport top (starting at more/lessbody > div.wp-site-blocks
which uses the theme’s global padding setting)
b) behind header (header.wp-block-template-part
which may be transparent or semi-transparent or opaque)
c) until upper part of of content area (main.wp-block-group
). - MUST: Custom dimensions per each hero image/video instance.
a) Width (mostly full body, but want the possibility to set this to content-width or wide-width (and fill rest with bg-color) ).
b) Min-Height + Focal Point of image within container
Note: Cover block does a + b perfectly.
c) OPTIONAL: Fixed Aspect Ratio
What I encountered and tried so far
- Plenty classic non-block themes with a tall header (ca 30-50vh) which combine main-menu + page-title + featured image as background image behind the whole header area.
Usually coming with two page template variants like page-with-hero and page-without-hero or a “? Use Hero” toggle option in the Inspector Panel > Page, so that you can decide on a page to page basis. E.g. Blocksy (in the demo: different hero image per pages: Home, Services, Menu) - In block themes it is easy to simply have no fixed title element in your page template and then individually per page put a cover block (using alignment = full-width, min-height as appropriate, e.g. 60vh) and put a title (semantically a div, cannot be changed) on top of the cover, or a h1 later in the page flow, what better suites the content/presentation.
a) But how do I get the content — which holds the hero-cover and everything else that follows — behind the header? Negative top margin? UI does not accept negative values. So I would add custom CSS to the block theme with Styles → Custom CSS (implemented in Gutenberg 14.8, will be in WordPress Core 16.2. So for now I tried in the web browser DevTools:main.wp-block-group
getsmargin-top = - 20rem
(offset value compensating header-height plus and global.wp-site-blocks
paddings. → Does not work well → stacking context issues (fiddled with z-index ofheader
andmain.wp-block-group
to no avail.
b) Even if that would work, with clamp() on the global margins, the header offset compensation strategy won’t work (or gets harder).
c) Is the solution to put the hero image in the header template with the Site Editor? But then I cannot edit it page per page in the WordPress Block Editor.
d) Is this only solve-able with block themes which foresee this need? d1) By wrapping the header and the content area into new element or
d2) Utilizing the existing common parent elementdiv.wp-site-blocks
and make it into a flex-container, which is set up in a way where the header area simply sits on top of the upper content-area?
What’s the clean way to do this in a block theme? And are there any already built that way?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Hero Image in Block Theme spanning behind header into upper part of content area’ is closed to new replies.