-
SummaryI've built a responsive slider, with multiple slides on-screen at once. The slides and page are high contrast, and I'm seeing a 1px bar of the previous slide on my screen when certain slides come into view, like this: I'm guessing it's a rounding error accentuated by dpr, and have started looking through the code, but wanted to see if it's a known problem and known to be unfixable - or if there's an easy known fix? For my use-case it wouldn't matter if the left edge of some slides was cut off by 1px to ensure nothing of the previous slide was visible, which would get round the rounding problems. Demo and platformsI've put together a code sandbox example (below) to demonstrate the issue. Please view it with the I'm seeing the error in Chrome 135 and Firefox 137 on macOS 14.6.1. In the example it happens only on a retina screen; on a non-retina screen the snapping is okay. If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationNo response CodeSandbox examplehttps://codesandbox.io/s/embla-carousel-generator-vanilla-forked-r8445d |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hi @pbowyer, I suspect this issue might be related to subpixel rendering quirks in the browser. One potential solution, not sure it will solve this though, could be to use However, there's a caveat: when the carousel (or its parent, like a modal) is transformed, I’ve had a task on my to-do list to explore a hybrid approach—using |
Beta Was this translation helpful? Give feedback.
-
Thanks for taking the time to reply @davidjerleke. I'm going to explore subpixel rendering and see what there is out there about these quirks, because that does seem to be the main cause of the problem. |
Beta Was this translation helpful? Give feedback.
-
And just like that, I think I've found a fix for this particular use-case: https://developer.mozilla.org/en-US/docs/Web/CSS/round. Thanks to CSS improvements last year there's the .embla__slide {
/* This is the fix - round the size to a whole pixel */
flex: 0 0 round(var(--slide-size), 1px);
} Now no white lines messing up my design 😀 Many thanks for your help in identifying the problem! Demo of the fix: https://codesandbox.io/p/devbox/embla-carousel-generator-vanilla-forked-x233fv |
Beta Was this translation helpful? Give feedback.
And just like that, I think I've found a fix for this particular use-case: https://developer.mozilla.org/en-US/docs/Web/CSS/round.
Thanks to CSS improvements last year there's the
round()
function. As I have the last slide hanging out of the viewport, I can round the widths of my slides to the nearest pixel and this won't cause me any problems. The specific change I made is:Now no white lines messing up my design 😀 Many thanks for your help in identifying the problem!
Demo of the fix: https://codesandbox.io/p/devbox/embla-carousel-generator-vanilla-forked-x233fv