amp-wp icon indicating copy to clipboard operation
amp-wp copied to clipboard

Amp Breaks Responsive Design of the Custom Logo in Twenty Twenty Theme

Open manuelschwartze opened this issue 6 years ago • 10 comments

I just noticed that the amp plugin breaks the responsive design of the custom logo in the Twenty Twenty theme. Adding this snippet as custom CSS solved the issue.

.header-titles { width: 100%; }

I hope this is the right place and way to report this.

manuelschwartze avatar Aug 26 '20 21:08 manuelschwartze

Could you provide more context about your setup? For example, the version of the plugin are you using, the template mode you have selected, a screenshot of the AMP page with the issue.

I've tried to replicate your issue with v1.5.5 and v2.0.0-RC2 of the plugin, but I see no visual inconsistencies when in Transitional or Standard mode when viewed from a desktop or mobile device. Likewise, when Twenty Twenty is used as a Reader theme with v2.0.0-RC2 active, I see no inconsistencies there either.

pierlon avatar Aug 26 '20 21:08 pierlon

Hi @pierlon Sure. I am running WP 5.5 with Twenty Twenty 1.5 and AMP Version 2.0.0 in standard mode.

Here is a screenshot of the site using Safari 13.1.2 in responsive mode without .header-titles { width: 100%; } in custom CSS . As you can see the logo image is not centered and I am able to horizontally scroll to the right.

screenshot

manuelschwartze avatar Aug 27 '20 10:08 manuelschwartze

@mmschwrtz unfortunately I'm still not able to replicate the issue. To be of further assistance, please share your Site Health info with us. You can do so privately via this form: https://forms.gle/PySNjhhxPLrJU6F1A

pierlon avatar Aug 27 '20 21:08 pierlon

I've found a way to replicate this. With the following custom CSS added:

@media (max-width:699px) {
 .site-logo .custom-logo-link img {
  width:365px;
  max-height: none;
 }
}

Here's what the non-AMP and AMP pages look like when viewed on a mobile device (viewport width < 700px):

Non-AMP AMP
image image

Both images have the same width and display CSS properties assigned, but the outcome is different as you can see above. This issue seems to be related to https://github.com/ampproject/amp-wp/issues/4418.

pierlon avatar Aug 29 '20 00:08 pierlon

This CSS is not part of Twenty Twenty, however. I see it is part of Twenty Nineteen, although the media query is not the same: https://github.com/WordPress/wordpress-develop/blob/0013f5979cb00ee9ad3ac5748b72880594bdbb1c/src/wp-content/themes/twentynineteen/style.css#L3804-L3809

@mmschwrtz Is that something you've added to your site via Additional CSS in the Customizer, for example?

As such, this wouldn't be a bug with Twenty Twenty directly, no?

westonruter avatar Aug 29 '20 02:08 westonruter

Yes, I forgot to mention that. It's most likely custom CSS added to the page and not a bug with Twenty Twenty. Also, it does not seem to be a regression introduced in v2.0, I can also replicate it in v1.5.5.

pierlon avatar Aug 29 '20 02:08 pierlon

Actually, I think this is behaving as intended. As stated in the layout system spec for the intrinsic layout:

The element takes the space available to it and resizes its height automatically to the aspect ratio given by the width and height attributes until it reaches the element's size defined by the width and height attributes passed to the amp-img, or reaches a CSS constraint, such as max-width.

In this case:

  • the image max-height is set to none, so there is no constraint on the height
  • the parent element does not have a CSS constraint set to limit the width or height of the image
  • the image width is set to 365px, so the image takes up all the space available space until it reaches that size according to its aspect ratio

So I wouldn't consider this as a bug, per se. There's no generic way of solving something like this, so I would say it's best left to the developer to resolve the issue.

Thoughts @westonruter?

pierlon avatar Aug 29 '20 05:08 pierlon

Yes, I think you are right.

@mmschwrtz Since you seem to have modified the core theme with custom CSS rules, you'll need to also add all that is required to prevent the intrinsically-sized image from overflowing.

westonruter avatar Sep 03 '20 18:09 westonruter

Hi @westonruter I have added some custom CSS rules but none that would explain this behavior:

figcaption.wp-caption-text {display:none;} div.footer-nav-widgets-wrapper {border-top: 0;} p.jp-relatedposts-post-date, p.jp-relatedposts-post-context {display: none !important;} hr.post-separator.styled-separator.is-style-wide.section-inner {height: 0px;color: #ffffff;} a.more-link {margin-top: 0 !important;} amp-img[lightbox] {cursor:pointer;}

I just noticed that the site in question is running the Twentig Version 1.1.2 plugin. Maybe this causes the issue?

manuelschwartze avatar Sep 07 '20 13:09 manuelschwartze

Indeed. That does seem to be where it is coming from. See https://plugins.trac.wordpress.org/browser/twentig/tags/1.1.2/inc/twentytwenty/index.php#L2795

$logo_responsive_width = get_theme_mod( 'twentig_logo_mobile_width' );
if ( $logo_responsive_width ) {
    $css .= '@media(max-width:699px) { .site-logo .custom-logo-link img { width:' . intval( $logo_responsive_width ) . 'px; height:auto !important; max-height: none; } }';
}

You might want to suggest that the plugin author add the necessary CSS to prevent the image from overflowing the available width.

westonruter avatar Sep 08 '20 00:09 westonruter