Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMP page for image attachment has wrong alignment for image #4735

Closed
pierlon opened this issue May 16, 2020 · 1 comment
Closed

AMP page for image attachment has wrong alignment for image #4735

pierlon opened this issue May 16, 2020 · 1 comment
Labels
Bug Something isn't working CSS WS:Core Work stream for Plugin core

Comments

@pierlon
Copy link
Contributor

pierlon commented May 16, 2020

Bug Description

The AMP page for an image attachment displays the image as centered, while the image non-AMP counterpart is left-aligned.

Expected Behaviour

AMP and non-AMP page for an image attachment should have the same alignment.

Steps to reproduce

  1. View the page for an image attachment.
  2. Compare the non-AMP and AMP version of the page

Screenshots

image

Additional context

  • WordPress version:
  • Plugin version:
  • Gutenberg plugin version (if applicable):
  • AMP plugin template mode:
  • PHP version:
  • OS:
  • Browser: [e.g. chrome, safari]
  • Device: [e.g. iPhone6]

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

@westonruter
Copy link
Member

Somehow this issue is caused by this rule:

amp-img:not([_]) {
    display: block;
}

This was added in #4421 to fix #4419:

/**
* Add style rule with a selector of higher specificity than just `img` to make `amp-img` have `display:block` rather than `display:inline-block`.
*
* This is needed to override the AMP core stylesheet which has a more specific selector `.i-amphtml-layout-intrinsic` which
* is given a `display: inline-block`; this display value prevents margins from collapsing with surrounding block elements,
* resulting in larger margins in AMP than expected.
*
* @since 1.5
* @link https://github.com/ampproject/amp-wp/issues/4419
*/
public static function add_img_display_block_fix() {
$method = __METHOD__;
// Note that wp_add_inline_style() is not used because this stylesheet needs to be added _before_ style.css so
// that any subsequent style rules for images will continue to override.
add_action(
'wp_print_styles',
static function() use ( $method ) {
printf(
'<style data-src="%s">%s</style>',
esc_attr( $method ),
// The selector is targeting an attribute that can never appear. It is purely present to increase specificity.
'amp-img:not([_]) { display: block }'
);
}
);
}

@westonruter westonruter added the Bug Something isn't working label May 18, 2020
@kmyram kmyram added the WS:Core Work stream for Plugin core label Aug 5, 2020
@pierlon pierlon added the CSS label Aug 28, 2020
@westonruter westonruter closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2023
@github-project-automation github-project-automation bot moved this to Backlog in Ongoing Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working CSS WS:Core Work stream for Plugin core
Projects
Archived in project
Development

No branches or pull requests

3 participants