-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix image alignment #5209
Fix image alignment #5209
Conversation
This fix requires testing in IE/Edge. These browsers don't support intrinsic values for |
.wp-block-image { | ||
float: right; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand properly, this fix PR is meant for the frontend, is this really necessary? we just merged #5142 that refactors how float work where the idea was to make floats work in a generic way in the editor not requiring specific handling per block.
Can you explain why do we need this specific handling? right now the block nodes (wp-block-image
) are not floated in master but their container is in a generic way to avoid having to do it in each block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know Ella and I discussed this also. The biggest challenge with adding an inline style is that it becomes impossible for a theme to override it without employing the I've recently been on a refactoring spree to simplify how we use floats. Previously we'd float the block itself, not the image inside the block. To do this we had to use crazy margin hacks to make images appear to be floating when in fact they weren't. As of #5142, however, we now use vanilla floats, using a simpler trick that allows simple wide and fullwide tricks, as detailed in this codepen https://codepen.io/joen/pen/oEYVXB?editors=1100 Aside from the simplification of markup, this can help address a number of issues we have around floats, which I'll take a look at today. The reason I mention is that if we are going to add an explicit But did you rebase properly? I could swear I added a But not in master. Edit: it's a bit hard to see what goes on in the above picture, but essentially the wide images is not clearing the floated gallery. |
@@ -177,8 +177,6 @@ export const settings = { | |||
|
|||
if ( width ) { | |||
figureStyle = { width }; | |||
} else if ( align === 'left' || align === 'right' ) { | |||
figureStyle = { maxWidth: '50%' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there have been discussions about whether to add this or not, not sure about the conclusion here though @jasmussen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep — mostly I'm in the camp of the fewer inline styles, the better, because themes can't override them without using !important
. So we should be very careful before we add inline styles like this.
@jasmussen: I'm note entirely sure what the issue is you're describing, but this branch definitely includes the changes from #5142. An alternative option may be to add the |
Sorry, took a deeper dive and yes, this does not appear to be a float clearing issue at all. But it does appear to be an issue with
I was also unclear here, sorry. The issue I'm describing is not directly a result of this particular PR, and doesn't need to be addressed as part of this PR. Perhaps there's even a better way. Here's the markup of a resized, floated image, with a caption:
What I'm asking for, is for the markup to be this instead:
or alternately this:
Only for resized images. The key difference being we add the explicit width to the caption as well. I do understand how that seems sub-optimal — why can't the What it does is to not float the But notice how the caption width is now unrelated to the Yet another alternative would be to add still more markup to the Image block. A la this:
Also not ideal. Feel free to chat me up if you need more explanations. I've been thinking about floats for more than a year now. |
This is definitely an important PR, as it addresses directly the addition of the |
This is still an issue @pento for the user in the support forums here: https://wordpress.org/support/topic/bug-align-center/. Would be great to work on getting towards a resolution. |
@karmatosed that issue was fixed separately in last weeks 2.3 release :) |
Hello guys! No, the bug is not solved. The bug is solved only on admin area but no when you publish the post. As you can see here: https://wordpress.org/support/topic/bug-align-center/ |
Fixes comment in #5209 (comment). Previous implementation assumed the theme would handle centering, just like it's traditionally handled alignleft and alignright classes, but since the aligncenter is now applied to the `figure` element, any theme that uses code like `img.aligncenter` won't work. Hence this PR.
Hi all – jumping in here with an outside perspective. I'm not up to speed on all of the background for why you've landed on the current markup for images in the image block, but it seems to me like we're reinventing the wheel quite a bit here and opening up some backcompat concerns that we need to be aware of. Currently, themes and plugins can generally make assumptions about the default markup for images and images with captions in post content since our default markup hasn't changed in forever. As #4898 illustrates, even core makes some assumptions about markup. As this gets wider use, I expect that we'll discover many more cases where people are either doing a It may be that the markup changes are warranted — and if so, there's no better time to do that than now — but if it's only going to be moderately different, I wonder if we'd be better sticking with the current markup patterns? |
@pento I made a new version of your pull request, essentially, here: #5973 @joemcgill wanted to loop in @mtias as he has the deeper insights, but to my understanding the image block comes with new markup that isn't filterable like the old is, and this is an opportunity to look at the semantics again, and in that situation figure and figcaption become natural upgrades to the semantics. Images inserted in the classic block retain their classic markup. |
Thanks @jasmussen, trying to take this opportunity to improve semantics seems sensible to me. I think I have two main concerns in this regard:
|
Looking into this more, and it looks like the issue that @skynever is having is due to the fact that his theme styles did not account for the change from a
Which, due to CSS specificity, will override the styles that are commonly used in themes for applying center alignment to images, i.e.,:
This is handled in #5706 by loading additional styles to fix image alignments. I'm of the opinion that WordPress should not be loading extra styles for this. I understand the reasoning articulated in this comment from the PR:
...but would suggest that a change in the markup that requires either theme updates or extra styles from WordPress should probably be handled through explicit theme supports option. We have precedence for this, in declaring HTML5 support for captions and galleries. |
Joe, you are correct, the centering issue is fixed. By the way if you have time, I would love your input and thoughts on #5973, ❤️ |
Hello @jasmussen image align center is not work in excerpt. So if i set featured image this featured image will be always fixed on the left not center, any idea to solve this? |
@jasmussen: Awesome, this PR has sadly languished. Closing, because this PR is old, has merged conflicts, and is superseded by #5973. |
In excerpt? I'm not completely sure what we are doing differently in Gutenberg with the excerpt. Can you try in the classic editor? Otherwise, feel free to ping me in Slack if you can, then we can work through it https://make.wordpress.org/chat/ — my username there is "@joen" |
* Fix various image width problems This fixes #3945 and #5213. It is a new PR that is meant to replace #5209. This PR is a work in progress. * Remove inline style for unscaled images. Also fix placeholder. * Restore float widths for blocks without intrinsice width Affects CoverImage, Gallery, Embed. This moves those styles to each blocks individual stylesheet. * Remove inline style on figure for scaled images With the presence of `fit-content` applied to the figure, the explicit inline style is no longer required.
Description
After #4898, there are some bugs in image alignment, because the
<figure>
element defaults towidth: 100%
, so WordPress'align*
classes have no effect on it.How Has This Been Tested?
Upload an image smaller than the post width, and change its alignment. View the results on the front end.
Checklist: