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.

CSS Grid + Swiper Wrapper - wrong width calculated

See original GitHub issue

This is a (multiple allowed):

What you did

A basic CSS grid setup with 3 columns setup on a wrapper. Carousel is set up within the 3rd column with a width of 1fr (which should take up 1fr of the remaining space of the max-width container). For code example see codepen showing issue. Code is direct replica of code in my development build.

Expected Behavior

Swiper wrapper is to take up the remaining space of the container instead of overflowing with the correct slidesPerView visible

Actual Behavior

Swiper wrapper is overflowing, with slidersPerView being ignored. Wrapper is showing width of entire width of elements.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:25
  • Comments:37 (2 by maintainers)

github_iconTop GitHub Comments

32reactions
mxwendtcommented, May 17, 2019

I had a similar issue and found a solution.

You can prevent Swiper from overflowing by adding an overflow: hidden to the parent element (in your case the .wrapper).

And there was also an issue with your grid column setup. .sidebar should have a value of 1 / 2 and .carousel a value of 2 / 3.

I updated your Codepen example: https://codepen.io/anon/pen/MdmxNp

25reactions
dungle-scrubscommented, Mar 1, 2021

One more workaround to add, as I’ve noticed something specific. If I have a 2-column grid (using grid-template-columns: 1fr 1fr), the crucial part is that the immediate child in the column must have overflow: hidden. Then, Swiper will calculate its width correctly no matter how far nested it is.

  • container (grid, two columns)
    • div (100% width, overflow hidden)
      • div
        • div
          • swiper

If the immediate child of the column is not set to overflow hidden, the width won’t be calculated correctly

This will break:

  • container (grid, two columns)
    • div
      • div
        • div (100% width, overflow hidden)
          • swiper
Read more comments on GitHub >

github_iconTop Results From Across the Web

Swiper - wrong width on init, correct width after resize
I set 4 slides per View, but it's calculating the width for 3 1/2 slides. I cleared everything except slidesPerView from my configuration...
Read more >
Swiper and CSS grid and/or flexbox - Framework7 Forum
I am desiring for “box1” to be responsive, to match the grid property “grid-template-columns: 1.25fr 1fr;”. Your change gave box1 a fixed width....
Read more >
Developers - CSS Grid + Swiper Wrapper - wrong width calculated -
CSS Grid + Swiper Wrapper - wrong width calculated.
Read more >
SwiperOptions | Swiper - v8.4.5
The beginning of the modifier CSS class that can be added to swiper container ... When enabled Swiper will automatically wrap slides with...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Implemented CSS font-size-adjust property (255927@main) ... Related properties sharing a computed value (r293602); Made word-wrap CSS property an alias of ...
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