Comments (8)
@eeeps with https://codepen.io/eeeps/pen/qBvmvwE I see stretched images in Chrome Canary 121 (I got an error with updating it seems), but resizing the window made the image switch to correct aspect ratio.
I downloaded a new Chrome Canary, which was version 122 (still an error with updating), and now the image is not stretched. So maybe it was a bug that was fixed after 121?
from html.
Adding the following CSS to the stylesheet fixes the issue for me:
If you also remove display: flex
from the parent, the images disappear. That was the original problem that contain-intrinsic-size
in the UA stylesheet was intended to solve. See #9448 (comment)
from html.
As I understand it, the problem here is that the object-fit
spec calls for contain
and cover
to look at the element’s natural aspect ratio.
Authors should be able to set this intrinsic size with contain-intrinsic-size
but there appears to be a Chrome bug preventing this from working, currently.
Once the Chrome bug is fixed, this should be work-around-able. However: would it be web compatible to have the <img width height>
attributes set the natural size of the <img>
in the same way that they do, for <video>
, which does not suffer from this problem? https://codepen.io/eeeps/pen/bGZWZBq
from html.
Actually this does appear to be fixable with contain-intrinsic-size
? I swear it wasn't an hour ago, but perhaps I just made a typo? https://codepen.io/eeeps/pen/qBvmvwE
The codepen I linked above (https://codepen.io/eeeps/pen/bGZWZBq) is also working "properly" for me now. An hour ago the first dog face (in the <img>) was squished to 2:1 within its 1:1.5 box, I promise! It had large green letterbox bars; I should have taken a screenshot.
from html.
Hmmm, I wonder if we should have width
and height
attributes, if both are set (on img
or the selected source
), be a presentational hint to contain-intrinsic-size
? Or should object-fit
work differently?
@LeaVerou @tabatkins @fantasai any advice, as editors of css-images?
cc @whatwg/css @progers @tcaptan-cr
from html.
Hmmm, I wonder if we should have
width
andheight
attributes, if both are set (onimg
or the selectedsource
), be a presentational hint tocontain-intrinsic-size
?
@progers @tcaptan-cr I see auto-sizes was unshipped in Chromium because of this issue (based on the referenced bugs), but the sites in question apparently don't have width/height attributes.
We could make auto-sizes do nothing if the img
doesn't have both width
and height
attributes, in addition to the preshint fix. I think that would address the web compat issue.
from html.
In my original example test case, it does look like the UA stylesheet was being applied and causing this issue, even though in my case the image markup does include width
and height
attributes. Adding the following CSS to the stylesheet fixes the issue for me:
img:is([sizes="auto" i], [sizes^="auto," i]) {
contain-intrinsic-size: auto none;
}
It makes me wonder if the UA stylesheet is being applied too broadly here.
from html.
Thanks for the context, @zcorpan. I guess the thing that is unclear to me is that even in @eeeps comment that you linked to, he specifically references images without height
and width
, whereas the UA stylesheet applies regardless of whether the dimension attributes are present.
from html.
Related Issues (20)
- Ability to configure whether script elements should execute for setHTMLUnsafe()
- `html` end tag omission HOT 3
- Navigation: Clarification on `ever populated` flag of DocumentState during apply the history step HOT 3
- Upcoming WHATNOT meeting on 2/8/2024 HOT 2
- Should dir=auto with no strong characters inherit directionality from parent or be ltr? HOT 10
- Navigation: DocumentState request referrer is not set for about:srcdoc
- `<callout>` element for callouts/alerts/admonitions HOT 35
- Proposal: HTML Attribute to state non-consent when scraping for training datasets HOT 1
- Can a task throw exceptions? HOT 2
- "run a classic script" returns completion records and throws HOT 1
- Session history step of top level navigable when child navigables traverse history HOT 1
- Should there be an opt-out for declarative shadow roots having `clonable=true`? HOT 27
- Should `<a target="_blank">` and `window.open` consume the transient activation? HOT 2
- `<img sizes="auto, 100px" loading="eager">`: `auto` equates to `100wv` but should ideally be ignored
- Constrain OffscreenCanvas with a placeholder canvas element HOT 8
- A way to run code before the next frame HOT 8
- New attribute for avoiding to autocapitalize text input fields HOT 1
- Autocomplete attribute value to indicate form input is third-party data
- Improve API of `insertAdjacent*()` methods HOT 2
- Why does popover hide when the popover attribute changed HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html.