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.

Use glide with flexbox

See original GitHub issue

Example project: https://codepen.io/dodozhang21/project/editor/DNxweB

I’m dynamically mout/destroy the glide based on breakpoints.

For breakpoint narrow desktop and higher, I need to add a right rail to the right of glide. So I used flexbox to create the layout. As the right rail width is fixed but the content width should flex.

.gridBContainer {
  @include narrow-desktop {
    display: flex;
    
    .galleryContainer {
      flex: 100 0 1px;
      margin-right: 20px;
    }
    
    .right {
      flex: 0 0 #{$right-rail-width};
      background: gray;
    }
  }
}

However it seems glide cannot figure out the width of the .galleryContainer without me explicitly setting a width on the container.

Is this a bug or am I doing something wrong?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:5

github_iconTop GitHub Comments

35reactions
michaelspisscommented, Apr 11, 2020

This can easily be fixed by setting the flex item’s min-width to 0. Example with inline css:

<div style="display: flex">
  <div style="flex: 1"</div>
  <div style="flex: 1; min-width: 0">
    <div class="glide">...</div>
  </div>
</div>

This happens because flex items have a min-width of auto - which messes with the calculations

0reactions
jiulongwcommented, Apr 5, 2020

Had the same issue. Setting explicit width kind of works but missed the flex part. After digging around I found a better solution for anyone who come across this.

The root cause is in flex box, JS code cannot figure out the correct width of a div. To solve this we can use an absolute positioned div to fill the flex div. We also need to use the aspect ratio hack to make the height of flex div correct.

Basically we need two wrapper divs.

<div class="flex-box">
  <div class="fixed-width"></div> <!-- e.g. thumbnail rail goes here -->
  <div class="flex-1-div">
    <div class="aspect-ratio-keeper"> <!-- wrapper 1 -->
      <div class="glide-wrapper"> <!-- wrapper 2 -->
        <div class="glide">...</div> <!-- actual glide goes here -->
      </div>
    </div>
  </div>
</div>
.aspect-ratio-keeper
  position: relative
  height: 0
  padding-top: 56.25% // use same aspect ratio for your slide

.glide-wrapper
  position: absolute
  left: 0
  right: 0
  top: 0
  bottom: 0
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create a Slider or Carousel in Minutes Using Glide.js
In this video you will learn how to create a slider or carousel using Glide.js. This is just a starting point, make sure...
Read more >
StaggeredLayout with FlexboxLayoutManager - Stack Overflow
I there any way to implement a staggered layout using google's Flexbox library similar to this. Layout implemented using StaggeredLayoutManager.
Read more >
A Complete Guide to Flexbox | CSS-Tricks
Our comprehensive guide to CSS flexbox layout. This complete guide explains everything about flexbox, focusing on all the different possible ...
Read more >
Flexbox's Best-Kept Secret - Medium
Using auto margins with Flexbox is an effective way to get all of the flexibility of css floats, without the nastiness of breaking...
Read more >
Using Flexbox layouts in UI Builder
Create a Flexbox layout in UI Builder to build powerful pages so ... Activate application restricted caller access ... Glide Server APIs.
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