simevidas,
@simevidas@mastodon.social avatar

I need help with CSS debugging:

Why is the image too wide, causing a horizontal scrollbar? This looks like a 100vw issue, but I don’t see that value anywhere.

https://www.jamiesitalian.rs/en/ji-serbia/

video/mp4

iamdtms,
@iamdtms@mas.to avatar

@simevidas These ruleset works for me, but it might be having another issue.

Hope it helps:

 main picture {  
 display: block;   
 overflow-x: hidden;  
}  
simevidas,
@simevidas@mastodon.social avatar

@iamdtms max-width: 100% on <img>

sarajw,
@sarajw@front-end.social avatar

@simevidas it feels like it must be to do with the vertical scrollbar, as there's no issue on my mobile browser in whatever mode...

db,
@db@typo.social avatar

@simevidas Okay, I take it back, that’s a good one! I have no idea so far…

db,
@db@typo.social avatar

@simevidas Maybe @eeeps has an idea since he investigated image sizing? I have a feeling it’s just built-in browser stuff in regards to how a <source> gets rendered in an <img> that fails to take account of the “Always show scroll bar” setting on macOS?

db,
@db@typo.social avatar

@simevidas @eeeps Alright, the default sizes on <source>, when missing, is 100vw:

https://html.spec.whatwg.org/multipage/images.html#parsing-a-sizes-attribute

simevidas,
@simevidas@mastodon.social avatar

@db @eeeps I’m not familiar with the details of responsive images, but 100vw seems like a bad default. Why make images cause horizontal overflow by default in browsers with classic scrollbars?

Of course, the web page can set max-width: 100% on <img> to avoid this issue, but the default should not cause issues to begin with.

db,
@db@typo.social avatar

@simevidas @eeeps In general, omitting sizes in such markup is an author error, and since sizes can’t use percentages, 100vw sounds like a sensible second choice that nonetheless should not be reached

simevidas,
@simevidas@mastodon.social avatar

@db @eeeps Isn’t setting it to 100vw the same as omitting it? That doesn’t fix the problem.

db,
@db@typo.social avatar

@simevidas @eeeps Yes, I mean the 100vw default from the HTML spec.

simevidas,
@simevidas@mastodon.social avatar

@db @eeeps So what is one to do to avoid the issue in HTML alone? Set sizes to the pixel width of the image and then add an extra 20px to the media condition to account for a potential scrollbar?

<source srcset="foo.jpg 800w" sizes="800px" media="(min-width: 820px)">

meduz,
@meduz@m.nintendojo.fr avatar

@simevidas @db @eeeps On the <img> tag, add width="100%" height="auto" and it will solve the issue.

It’s unrelated to the use of picture: if you move the img outside of picture, you’ll get the same behavior.

simevidas,
@simevidas@mastodon.social avatar

@meduz @db @eeeps That’s no longer valid HTML, so it’s probably not a good idea to use it.

eeeps,
@eeeps@front-end.social avatar

@simevidas @meduz @db Responsive images SHOULD have extrinsic widths; sizes is supposed to be a hint of the extrinsic size, and sometimes I worry that it was a mistake to make it also affect the intrinsic size, but – what else should the default intrinsic size of a responsive image be? I don't have a better answer.

simevidas,
@simevidas@mastodon.social avatar

@eeeps @meduz @db The problem is that the default is 100vw, which can cause the page to overflow horizontally in browsers with classic scrollbars. Maybe a better default would be the width of the ICB (initial containing blog)? That would fix the potential overflow issue (since the width of the ICB decreases when scrollbars are present).

eeeps,
@eeeps@front-end.social avatar

@simevidas @meduz @db is the width of the initial containing block known before layout? (The presence or absence of scrollbars can’t be, right?)

simevidas,
@simevidas@mastodon.social avatar

@eeeps @meduz @db By default, classic scrollbars are automatic (they only appear when they’re needed), so the browser cannot know before layout what the final width of the ICB will be.

If responsive images resized with the ICB, that would cause layout shifts in the vertical direction I guess, so that’s not good.

eeeps,
@eeeps@front-end.social avatar

@simevidas @meduz @db Right, sizes is there to give a value before layout that's a hint of the after-layout width. If it changes after layout, you could get double-loads, which defeat the whole point.

Is the concern what the platform can do for users when authors make the mistake of omitting CSS, like this? Or is there an unmet use case around "HTML-only" responsive images, that you think is important?

simevidas,
@simevidas@mastodon.social avatar

@eeeps @meduz @db I think that responsive images should work well without requiring any extra CSS.

If the author defines image sources via srcset and width descriptors (srcset="example.jpg 1000w, etc.") and nothing else (no sizes attribute, no CSS), then the browser should not make the image 100vw wide, but slightly smaller.

This could be achieved by defaulting the sizes attribute to

100vw - 16px (default body margin) - scrollbar size (only in browsers with classic scrollbars)

simevidas,
@simevidas@mastodon.social avatar

@eeeps @meduz @db 100vw is just a bad value (because viewport units ”assume scrollbars never exist”). Authors should not use 100vw to set element widths, and the HTML standard should not use it either for its features.

In the future, it will become possible to fix 100vw (https://mastodon.social/@simevidas/112079593017732587), but right now it should still be avoided, so it’s not good that responsive images use it by default.

eeeps,
@eeeps@front-end.social avatar

@simevidas @meduz @db I'm not sure if this is fixable soon, in a web-compatible way. Some images (like the one you found) are depending on the intrinsic size, and folks might be surprised at some new whitespace / consider their layouts "broken".

I'm doubting that the fix you mentioned will fix this, because it depends on other CSS, and srcset selection can't depend on any CSS. I guess this will end up like 1em meaning different things in different contexts?

db,
@db@typo.social avatar

@eeeps @simevidas I found it intriguing that sizes influences the layout width, so I pored over the HTML spec to get a better picture. Thanks for bringing these things up, fun times with the web platform!

https://danburzo.ro/responsive-images-html/

simevidas,
@simevidas@mastodon.social avatar

@db I’m not sure I like the term “density-adjusted natural dimensions”. “Adjusted” and “natural” feel like opposites to me. When something is adjusted, it’s no longer natural. If I had to guess, I’d say that “natural” is the image’s own dimension, outside of the browser. This is unless the density adjustment happens in the image’s own EXIF data, and the browser just reads that data without making any further adjustments, which I don’t think is happening in this case.

simevidas,
@simevidas@mastodon.social avatar

@db

> Instead of describing the preferred image densities, width descriptors (using the w suffix) declare the original width of each of the image sources.

So the image’s own dimensions are referred to as ”original”. That’s different from “natural”, right? Or is “original” the same as “natural”, which are different from “density-adjusted natural”?

simevidas,
@simevidas@mastodon.social avatar

@db

> sizes="(min-width: 400px) 10em, 80vw"

> On a larger screen that’s, say, 1920 pixels wide, our image is intended to be displayed at a width of 10em

Not screen but viewport. The user may resize the browser to be narrower than 400px even if the screen is 1920px wide.

simevidas, (edited )
@simevidas@mastodon.social avatar

@db

> Safari. The DPR is fixed

So if the website provides ultra-high-density image sources, and the user zooms the page, Safari won’t use those sources, even after page reload. In other words, at high page zoom levels, images on some websites will be noticeably blurrier in Safari than in Chrome and Firefox. That sounds like a bug to me.

simevidas,
@simevidas@mastodon.social avatar

@db Makes me wonder if browsers should update image sources when the user zooms in “visually” (the other type of zoom in desktop browsers)

video/mp4

db,
@db@typo.social avatar

@simevidas Yeah, that would be amazing. I haven’t looked closely at how pinch-zooming is implemented, but it does look like it works by increasing the size of the CSS pixel

simevidas,
@simevidas@mastodon.social avatar

@db Yes

> The scale transform of the visual viewport is often referred to as "pinch-zoom". Conceptually, this transform changes the size of the CSS reference pixel but changes the size of the layout viewport proportionally so that it does not cause reflow of the page’s contents.

https://drafts.csswg.org/cssom-view/#visual-viewport

simevidas,
@simevidas@mastodon.social avatar

@db I just noticed that “resizing the viewport” is kind-of ambiguous.

If the user resizes the browser window, that will change the dimensions of the viewport in device pixels.

If the user zooms the page, that will change the dimensions of the viewport in CSS pixels.

So resizing the browser and zooming the page can both be considered as ways of resizing the viewport.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • GTA5RPClips
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • cubers
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • osvaldo12
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • everett
  • Durango
  • cisconetworking
  • khanakhh
  • ethstaker
  • tester
  • anitta
  • Leos
  • normalnudes
  • modclub
  • megavids
  • provamag3
  • lostlight
  • All magazines