Non-visible slides when using CSS grid in combination with `loop: true`
See original GitHub issueBug is related to
- embla-carousel (core package)
Embla Carousel version
- v6.2.0
Describe the bug
When CSS grid (as described here) is used in combination with loop: true
, the left
offset of the last or first slide is not properly calculated and it leads to not showing the first/last card inside the carousel.
The calculation here is correct for flex-box: https://github.com/davidjerleke/embla-carousel/blob/master/packages/embla-carousel/src/components/SlideLooper.ts#L49-L63
But when display: grid
is used for the embla__container
the value left
needs to be set relative to each slide/card instead of the container width (+ gaps).
CodeSandbox
https://codesandbox.io/s/embla-carousel-loop-vanilla-forked-4b75xf?file=/package.json
Or as standalone example: https://4b75xf.csb.app/
Steps to reproduce
- Open https://4b75xf.csb.app/ (Carousel with loop: true and CSS Grid)
- Last card is shown on the left
- Click on previous button
- Now the first card is not shown on the right
Expected behavior
That the last / first card is shown when looped using CSS grid.
Additional context
Initial Load: missing last card
Clicking on previous button: first card is not shown
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Things I've Learned About CSS Grid Layout
Grid is for layout of items in two dimensions – rows AND columns. They can be combined as well. You can turn a...
Read more >CSS Grid Layout and progressive enhancement
In this guide we will walk through a variety of strategies for support. The supporting browsers. Other than in Internet Explorer, CSS Grid...
Read more >CSS Grid + Swiper Wrapper - wrong width calculated #2914
You can prevent Swiper from overflowing by adding an overflow: hidden to the parent element (in your case the .wrapper ). And there...
Read more >Carousel · Bootstrap v5.1
A slideshow component for cycling through elements—images or slides of ... <span class="carousel-control-next-icon" aria-hidden="true"></span> <span ...
Read more >CSS Grid Layout Module Level 1 - W3C
By combining media queries with the CSS properties that control layout of the grid container and its children, authors can adapt their ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@klipstein I’m working on Embla v7 now and this bug will be solved there:
@davidjerleke works great! The only small issue I’ve seen in my quick test was, that an applied grid gap (CSS
gap: 10px
) was not set between last slide and first slide when loop was used. But this can be fixed easily with a margin.