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.

Usage with (grid) gap spacing

See original GitHub issue

Hey,

Thank you for such a delightful library!

Would you consider adding support for creating spacing using grid-gap or gap properties? Currently I’m using padding and margin like in the examples which works just fine for my use cases but having support for gap would make it even easier.

Current issue when using gap is that the spacing seems to not be calculated into the transform so the last slide is ‘cut off’ as the scroll is calculated if it was with no spacing between slides.

// Current
.embla__container {
  display: flex;
  margin-left: -20px;
}
.embla__slide {
  position: relative;
  min-width: 80%;
  padding-left: 20px;
}
// Alternate
.embla__container {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 50%;
  gap: 20px; 
}
.embla__slide {
  position: relative;
}

  // or
  
.embla__container {
  display: flex;
  gap: 20px;
}
.embla__slide {
    position: relative;
    width: 50%;
  }

Now as I posted it I can see that using margin and padding it is the same or less lines of code but it doesnt feel as clean as just putting gap: 20px;

Also forgive me as I haven’t really looked into the source code to see if and how could it be implemented. I would like you know your opinion on this.

Thanks, Raf

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rkumorekcommented, Sep 27, 2022

@davidjerleke

Thank you for this.

This is a basic example: https://codesandbox.io/s/embla-carousel-vanilla-github-issue-148-forked-zht4h And it seems to work great with either grid or flex gap’s.

Sadly I cannot remember my code from back when I originaly tried that but this is close if not exactly what I wanted.

1reaction
davidjerlekecommented, Mar 9, 2021

Thanks Raf (@rkumorek), I’ll create a CodeSandbox for you and I’ll let you know when it’s ready.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gap - CSS: Cascading Style Sheets - MDN Web Docs
The gap CSS property sets the gaps (gutters) between rows and columns. It is a shorthand for row-gap and column-gap.
Read more >
CSS grid-gap property - W3Schools
The grid-gap property defines the size of the gap between the rows and columns in a grid layout, and is a shorthand property...
Read more >
Minding the "gap" | CSS-Tricks
The gap property is just one part of the empty space created between boxes in a layout container. margin , padding , and...
Read more >
Aligning the grid with space-around and space-between
In this example I am creating a four column track grid, the tracks have absolute sizes and in total are smaller than the...
Read more >
CSS | grid-gap Property - GeeksforGeeks
The grid-gap property sets the size of the gap between the rows and columns in a grid layout. It is a shorthand property...
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