• Resolved Ted

    (@taw22ala)


    I’m looking for “How to” support rather than fixing something broken, so I hope this is a reasonable place for this post. So much has changed with WordPress 6, and I’m very new here, but trying to learn. I have read (but unsure how much I truly understand) about using PHP and CSS to present different formatting on desktop vs mobile, but it all seems to be written for classic themes rather than block themes.

    I’m using WordPress 6 with a modified Twenty Twenty-Two theme installed offline via “Local by Flywheel.” I want to have a background for pages on desktop and have customized a template using a “Cover” block as the first element. The rest of the page is built in the group within the cover block. However, on mobile (phones) I would like to allow the group within the “Cover” block to be displayed full width – I think essentially ignoring the padding of the cover.

    Is it possible to assign a custom CSS class to the cover element and use @media to remove the cover padding below a certain threshold viewport width? I feel like I’m so close – but I may be totally off base and would appreciate some guidance.

    Thank you,
    taw

    • This topic was modified 2 years, 5 months ago by Yui. Reason: moved to "developing with wordpress"
Viewing 6 replies - 1 through 6 (of 6 total)
  • Varshil

    (@varshil151189)

    Hello @taw22ala ,

    For the mobile devices, instead of cover, you can change it to “contain” in @media query.

    Thread Starter Ted

    (@taw22ala)

    Thank you, Varshil,

    You definitely put me on the right track to get the look I want.

    I placed the following CSS into the “Additional CSS” menu of customize.php:

    
    @media screen and (max-width: 700px) {
    	#page-cover-block {
    		display: contents !important;
        }
    }
    

    However, this has caused another issue: the mobile navigation menu no longer works. The hamburger menu displays, but can’t be clicked.

    The default break point for the mobile menu in Twenty Twenty-Two is ~768px so it is possible to narrow the browser width to the point that the mobile menu appears and verify that it is working properly, then further narrow the browser width until the background cover image disappears as effected by the @media query above and confirm that the mobile menu no longer works.

    I’ve read several web articles regarding the usage of @media query, but I have yet understand the conflict with the mobile navigation menu.

    I’m open to further suggestions.

    Thanks,
    taw

    Varshil

    (@varshil151189)

    Hello @taw22ala,

    Can you please provide the URL so that i can check further.

    Thread Starter Ted

    (@taw22ala)

    I don’t think that will work. It’s running on a “Local by Flywheel” installation and not a publicly accessible web server. I don’t have a staging site. I’m trying to learn as much as I can offline before going live on a production site. Nevertheless, the URL is: https://fbcwhiteplains.local

    I will attempt to spin up a test site on “instawp” later this week to see if I observe the same behavior there and hopefully be able to test this on an real mobile device rather than narrowing the window of a desktop browser.

    Thanks for your help.
    -taw

    Thread Starter Ted

    (@taw22ala)

    **Update**
    I believe I have replicated the issue on this test site: https://melodicbottle.s4-tastewp.com/

    Some of my edits are not yet available on my mobile device, but I think that’s a caching issue. When the media query kicks in and changes the display mode of the cover block the navigation links in the header no longer work.

    I hope this helps identify the issue.

    Thank you,
    -taw

    Thread Starter Ted

    (@taw22ala)

    I have found something that works, but there must be an easier way! It appears the cover block overlays the content with a transparent background layer (background-dim) which blocks clicking on links behind the layer.

    @media screen and (max-width: 700px) {
    	#page-cover-block {
    		display: contents !important;
    		padding-left: 0px !important;
    		padding-right: 0px !important;
        }
    	.wp-block-cover-image.has-background-dim:not(.has-background-gradient)::before, .wp-block-cover-image .wp-block-cover__background, .wp-block-cover-image .wp-block-cover__gradient-background, .wp-block-cover.has-background-dim:not(.has-background-gradient)::before, .wp-block-cover .wp-block-cover__background, .wp-block-cover .wp-block-cover__gradient-background{
    		opacity: 0;
    		z-index: -1 !important;
    	}
    	.wp-site-blocks {
    		padding-left: 0px;
    		padding-right: 0px;
    	}	
    }

    I’m concerned that the complexity of this custom CSS could come back to haunt me later.

    Since my original question has been answered and I have a working resolution for the resulting problem of navigation links not working, I will mark this as resolved. However, I’m open to suggestions of a better resolution.

    Thanks,
    -taw

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do I make a cover block on desktop but not on mobile?’ is closed to new replies.