-
Notifications
You must be signed in to change notification settings - Fork 35
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
The sizes="" attribute only works with width-constrained images #86
Comments
I had planned to do exactly this, but I couldn't come up with an elegant way to do height-based selection. I didn't give it a ton of thought, though - it's very possible for there to be a good method that I just didn't come up with. I'm open to doing this if we can figure it out. Dealing with both width and height is quite a bit more difficult, but not impossible, particularly if we just allow something like |
Wait, I think I'm dumb. The w unit in a source list isn't used for "selection" directly. It specifies the width of the image source in image pixels; once you know the size of the So, using height in Doing cover/contain constraints is identical, except we can't tell a priori whether we'll be calculating the density from the width or the height, as that depends on the relative aspect ratios of the viewport and the image source. So, concrete proposal: We add an optional "h" unit to the We extend the grammar of
The MQ part of We change the algorithm to We then change the algo to |
So, once again, trying a (basic) example.. does this make sense: <picture>
<source sizes="(max-width: 30em) contain 30vh, (max-width: 50em) 50vw"
srcset="pic400.jpg 400w 200h, pic800.jpg 800w, pic1200.jpg 1200w">
<img src="pic400.jpg" alt="The president giving an award.">
</picture> Let's say I'm on an IPhone 5 (320 x 568px viewport, DPR: 2.0):
Not sure if I'm using the right markup, but does that look about right? It seems like there would be a lot of edge cases to cover once we get into both vw/vh in |
The It sounds like, from the following text, that you meant to say |
@tabatkins - the proposal sounds great (and would also resolve #85). One question regarding height based sizes - what do we do with percentage based lengths? Can we simply treat them as percentages of the viewport height (so, identical to vh)? e.g. in |
Yeah, definitely. |
This looks great. Modes + sensible defaults, requiring no change to the already-proposed syntax to get the already-propsed functionality... perfect! Thinking through the syntax and some edge cases with my own example... <picture>
<source
sizes="(width < 32em) contain, (width >=32em) contain 80vw calc(100vh - 10em)"
srcset="full.jpg 2048h 1024w, half.jpg 1024h, quarter.jpg 512h, eighth.jpg 256h" />
<img src="eighth.jpg" alt="¡Obama mambo!" />
</picture> In "cover" or "contain" modes:
|
Following a cover/contain keyword, you must supply either zero or two lengths. Zero is identical to supplying Hmm, good point on none of them having both lengths - you need the aspect ratio so you can compare it with the ratio of the contain/cover rect. I'll have to think on this. Regarding unneeded dimensions, such as giving a However, it will still affect the intrinsic size of the image. Since the canonical ratio is taken from the first such image, in your second example the intrinsic width will be 100vw and the intrinsic height'll be 341.3vw ( |
If we're going to discard |
Oh yeah, that makes sense. On Sat Jan 04 2014 at 1:25:09 PM, eeeps [email protected] wrote:
|
I think we should wait with adding this until the current proposal has implementation experience. If I recall correctly from the picture face-to-face in Paris last year, there was consensus that height-based selection is rare and does not need to be supported (yet). |
Yeah. Actually I think we should wait with adding new stuff until what we have now is implemented in WebKit, Blink, Gecko and IE. If we add too many things we risk vendors rejecting the whole thing. "Baby steps"... |
+1 to shipping piecemeal, so long as we keep in mind that it might make feature testing a little more complicated (we can test for |
That's where future-compatible error handling comes in. It might be a bit ugly to test for it, and #152 would make it async, but it should be possible. For instance |
+1 on adding an |
Or in short it could become handy when |
+1 for adding |
It's possible to hack this logic in today, but it's ugly. <img sizes="(min-aspect-ratio: 4/5) 80vh"> |
+1 for h in srcset on the img tag. The browser currently fetches the wrong image for a height constrained Lightbox viewer which, of course, isn't meant to scroll. h is the height of the viewport. In order to find best size and only providing widths i have to calculate the best width myself. |
Let's continue this discussion in whatwg/html#2973 Links to sites that would benefit from this, so a solution can be evaluated against real-world cases, would be very useful. |
(Moved from #85, where Yoav was suggesting an 'h' descriptor within the sizes="" attribute for completely different reasons.)
Could such a descriptor also enable height-based selection? I'd be all for that, if there's an elegant way to integrate it into the syntax and if it doesn't complicate the choosing algorithm too much...
?
While height-constrained layouts (especially responsive ones) aren't common, they're out there. It's much more common to see slideshow modes that constrain on both height and width. To accommodate that sort of thing, though—defining boxes instead of lengths—the syntax + the source selection might have to get a bit hairy...
The text was updated successfully, but these errors were encountered: