-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Site icon: Fix site icon styling to display non-square site icons within a square button #37570
Site icon: Fix site icon styling to display non-square site icons within a square button #37570
Conversation
James and Joen, I've added you both as reviewers if you get a chance, since you've given feedback to or contributed to the site icon recently 🙂 |
Size Change: -511 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
This tested well for me with wide, tall, and square images in both post and site editor contexts. Technically this looks like a good solution to me, but will hold off giving it a ✅ until it has had design feedback. |
My goodness, I hadn't even noticed that the hover style for a customized logo had changed! Here are GIFs to help the conversation along. In trunk, a landscape image remains landscape, just scaled down. It has a focus style, and it zooms way in on hover: This branch is the same, only the landscape image is soft-cropped to be square, regardless of its original aspect ratio: Just looking at the before and after, this is better, the image should be square. 👍 👍 — I personally think the hover style might be a bit jumpy, but it's fine, and it's separate. In principle the code looks good, however it seems like you should be able to accomplish the square crop by combining the same width and height with |
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 noted in my testing that you could have probably accomplished the same square icon with object-fit: cover;
. I would encourage a quick code sanity check to see if that's actually better, as that would afford the alt text to remain. Whether that's actually better for a screen-reader, to read a button with an image inside, or to just read a button, I can't say for sure.
But just as a before/after enhancement, this one is good to go.
border-radius: $radius-block-ui; | ||
background-size: cover; | ||
margin-top: -1px; |
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.
Excellent eye. Interestingly, when you're just toggling off that minus 1 margin in the inspector, it makes the site icon look vertically uncentered when it's on:
However when you zoom in and look at the details, you can see that it has to have that negative margin in order to horizontally align with the other buttons in the toolbar. With negative margin:
Without negative margin:
This is, per your instinct, related to the dark square being 61px tall. That math comes $header-height + $border-width, so that the black area covers the gray border below the top-bar.
So which do we keep? I don't have a strong opinion, but I appreciate your attention to detail, so probably do keep it. But I'd add a small comment above, something like // Compensate for the top-bar border.
, and then change 1px
to $border-width
instead.
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.
Might it be neater to make the black square 60px tall, then add a shadow to hide the grey border? Then we don't need the awkward negative margin.
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.
Thanks for the detailed approach here! I had a go at switching to 60px tall and using a shadow to hide the grey border. Unfortunately the styling in the site editor then wound up being a bit unreliable due to the z-index
stacking order. With 60px
and box-shadow, from time to time the shadow would pop out / a white line would be visible:
I've gone with adding the inline comment and using $border-width
instead of the hard-coded 1px
, and we can always look at switching to the 60px
approach in a follow-up if we'd like to tweak further.
border-radius: $radius-block-ui; | ||
background-size: cover; | ||
margin-top: -1px; |
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.
Same as above, could use a comment and a variable.
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.
Switched to using the variable, and added a comment.
Thanks for the review @jasmussen!
Yes, I keep forgetting that we can use I liked the idea of using the |
…hin a square button (#37570) * Fix site icon styling to display non-square site icons within a square button * Switch back to using an img element, use object-fit instead
Fixes #37564
Description
Following on from the site icon feature introduced in #35892 this PR fixes the styling for the site icon in the W button so that it displays non-square site icons within a square button. The fix does the following:
div
instead of animg
tag, and set the image as a background image with background size ofcover
.Note: I needed to add the
-1px
on the top margin to get the image to be centred correctly within the border as below:I think this is because the container is
61px
high instead of60px
to deal with the grey border, so getting the position exact along with the scale animation is slightly tricky. Let me know if anyone thinks this needs tweaking further!How has this been tested?
To quickly add a non-square site icon:
Use as site icon
in the sidebar inspector controls.Also, I checked that the styling when no icon is set appears to be unaffected (to test this go to:
/wp-admin/customize.php?autofocus[section]=title_tagline
and clear the existing site icon, then reload the post and site editors)Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).