Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Images won't fit flex container on chrome
I browse deviantArt from time to time and I wanted to make images display bigger, because there is so much useless whitespace on that site.
On first glance that would be simple - remove the set dimensions of the image element and the overly conservative srcset
.
Because it's a react site, and will reset the style any time you resize the viewport, I use some agressive css. The site's style already includes max-width: 100%
and max-height: 100%
, which are also important.
Here's the changes in userscript form
// ==UserScript==
// @name deviantArt expand images
// @version 1.0
// @grant GM_addStyle
// @match https://www.deviantart.com/*
// ==/UserScript==
document.querySelector('._28lPU').removeAttribute('srcset')
GM_addStyle(`
._28lPU {
height: unset !important;
width: unset !important;
}
`)
Alternatively, just open dev tools and delete these properties manually. Here's a page to test on: https://www.deviantart.com/hexanity/art/Helldivers-2-Orbital-bombing-1039305812
Based on what I know about flexbox and images, this should allow the image stretch up to it's native size to fill its flexbox container.
However this doesn't happen on chrome. Image remains tiny. Works as expected in firefox.
I tried to isolate the problem, but was unable to: https://jsfiddle.net/n9k2853c/
There's a few things I'm looking for here:
- This is a bug in chrome, right? (And is not my understanding or firefox that is broken?)
- Help isolating the problem, so perhaps it can be reported.
- Help finding a workaround.
1 answer
#3: I still don't know what exactly is going on, but experimenting today, I found a workaround at least:
align-items: normal;
on the container and object-fit: scale-down;
on the image.
Due to the way object-fit works, it circumvents the problem on chrome.
#1:
But this does highlight another inconsistency. The description of scale-down
is:
Size the content as if none or contain were specified, whichever would result in a smaller concrete object size.
This statement is lifted directly from the spec, but it is not true on chrome, providing another hint that it is indeed a bug! none
behaves differently than scale-down
on chrome! Example - though demonstrating the problem will depend on the resolution of your screen.
0 comment threads