question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-visible slides when using CSS grid in combination with `loop: true`

See original GitHub issue

Bug 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

  1. Open https://4b75xf.csb.app/ (Carousel with loop: true and CSS Grid)
  2. Last card is shown on the left
  3. Click on previous button
  4. 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

Screenshot 2022-02-21 at 17 54 48

Clicking on previous button: first card is not shown

Screenshot 2022-02-21 at 17 54 55

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
davidjerlekecommented, Apr 9, 2022

@klipstein I’m working on Embla v7 now and this bug will be solved there:

1reaction
klipsteincommented, Jun 30, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found