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

Image caption alignment in wrong position. #13684

Closed
paaljoachim opened this issue Feb 6, 2019 · 7 comments
Closed

Image caption alignment in wrong position. #13684

paaljoachim opened this issue Feb 6, 2019 · 7 comments
Labels
[Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended

Comments

@paaljoachim
Copy link
Contributor

paaljoachim commented Feb 6, 2019

Describe the bug
Default alignment for image. Add caption. It shows up in the wrong place.

To Reproduce
Steps to reproduce the behavior:

  1. Add an image.
  2. Add a caption.
  3. See if it aligns correctly with the image or if is aligns with the white image block space area.
  4. Also check the frontend.

Expected behavior
Video embed caption code is now finally aligning captions correctly.
#11441

Screenshots
Backend Gutenberg:
screen shot 2019-02-05 at 23 15 10

Aligns to the white image block space and not the image.
screen shot 2019-02-05 at 13 19 49

I wrote caption centered. For the caption is centered to the white image block space and not the image itself.
screen shot 2019-02-05 at 13 20 08

Frontend
screen shot 2019-02-05 at 13 20 22

Desktop (please complete the following information):
Mac OSX 10.13.6
Chrome
Gutenberg version 4.9.

@youknowriad

@swissspidy swissspidy added [Type] Bug An existing feature does not function as intended [Block] Image Affects the Image Block labels Feb 7, 2019
@draganescu
Copy link
Contributor

Hi @paaljoachim I was able to reproduce this only when selecting "Image Size" from the inspector.

screenshot 2019-02-18 at 17 59 53

If I resize using the handles the caption remains centered to the image:

screenshot 2019-02-18 at 18 02 38

Is this how you did it, using the Inspector "Image Size" dropdown or manually resized the image?

Also, the yep, misalignment is visible on frontend too.

@paaljoachim
Copy link
Contributor Author

Hey @draganescu

I just checked. Image has default alignment and the image is in full size mode.

Backend:
screen shot 2019-02-18 at 17 33 14

Frontend:
screen shot 2019-02-18 at 17 33 33

When I select Wide Width alignment then it looks correct.
screen shot 2019-02-18 at 17 34 49

@draganescu
Copy link
Contributor

draganescu commented Feb 19, 2019

Apparently this is as intended. The image block has a figure with two children and img and a figcaption. When the image is smaller than the block's box, but not floated (default align) the figure is displayed as block, thus the figcaption will be centered to the larger box, the figure, not the image.

When the image is floated (not default align) or resized, then:

  • the image's figure element gets a div wrapper
  • the figure and the figcaption elements are displayed as table and table caption respectively
  • this makes the caption align to the image's size

Maybe @jasmussen could chime in with some advice as to why we don't display the figure as table by default and the figcaption as table-caption by default, but only when the wrapper is present:

	.alignleft,
	.alignright,
	.aligncenter,
	&.is-resized {
		display: table;

		// The figure is born with left and right margin.
		// We remove this by default, and then customize it for left, right, and center.
		margin-left: 0;
		margin-right: 0;

		> figcaption {
			display: table-caption;
			caption-side: bottom;
		}
	}

Both in the editor and the front end using the table display for the figure and the figcaption elements by default, aligned or not aligned, resized or not resized, seems to work ok, but I am unsure yet if it yields other problems.

@jasmussen
Copy link
Contributor

Okay had to walk down memory lane to find the reasons for this.

Turns out we tried it, and punted it. #7721 (comment)

The pertinent bit:

In general we use a display: table; trick to get the caption to size itself according to the image. This works because of the unique rules of the table. However if an unfloated image follows a floated image, this means the unfloated image can size itself down to "fit in the available space", which is not what we want.

As I mention in the comment there, it is worth revisiting. But it may not be as simple as just applying the table property to the image block across the board. So for any PRs you make, please be sure to try a multitude of different image size & float configuations. Notably:

[small image, floated, with big caption]
[small image, not floated, with big caption]

And be sure to compare before and after.

@paaljoachim
Copy link
Contributor Author

I retested this by using various image alignments and the caption is now aligning correctly in Gutenberg and on the frontend. I will go ahead and close this issue.

@paaljoachim
Copy link
Contributor Author

paaljoachim commented Aug 23, 2019

Resizing the image directly using the handlebars automatically adjusts the caption area. Resizing the image using medium or thumbnail does not adjust the caption.
I will add a new issue for this specific bug.
#17162

@sparkbold
Copy link

experienced the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants