slick icon indicating copy to clipboard operation
slick copied to clipboard

Slick not working with CSS grids fr-units (fractions)

Open svirmasalo opened this issue 7 years ago • 24 comments

When using fr-units within css grid, Slick can't determine the width properly. Instead correct width, it makes it huge.

====================================================================

Here's the bug in action: https://codepen.io/virmasalo/pen/XgVzrM

====================================================================

Steps to reproduce the problem

  1. Create slick using css grid and px -units
  2. Change px-units to fr-units

====================================================================

What is the expected behaviour?

Work like it does with px or other typical units.

====================================================================

What is observed behaviour?

Slick can't calculate the width properly, but instead gives a huge value for it.

====================================================================

More Details

  • Firefox latest
  • Latest jQuery & Slick

svirmasalo avatar Jun 28 '17 18:06 svirmasalo

I have this problem too. Can you solve this?

alexd73 avatar Jul 11 '17 17:07 alexd73

Confirmed this behaviour with grids. It doesn't seem to be limited to fractional units in particular. When using "auto" width, it sets the slick-track element's style to width: 2.32644e+8px; transform: translate3d(-7.15828e+7px, 0px, 0px); Looks like it's trying to do some kind of javascript magic that doesn't take grids into account.

Check out: https://jsfiddle.net/o8ggsrny/1/

Looks like it's caused by this line in setDimensions: _.$slideTrack.width(Math.ceil((_.slideWidth * _.$slideTrack.children('.slick-slide').length)));

Setting an explicit width for the column fixes the problem. I was able to work around this and still have a responsive design by setting my columns like so: grid-template-columns: minmax(100px, min-content) calc(100vw - 463px);

hackel avatar Aug 14 '17 22:08 hackel

For what it's worth, in our Slick setup we've only had this issue on iOS Safari 10, not 11. We've managed to fix it by setting a width: 100vw value on the .slick-list element.

sephie avatar Nov 21 '17 12:11 sephie

Anyone have an update on how to fix this issue? I'm trying to shove a slick slider inside a css grid that is split into 3 x 33% columns.

Coop920 avatar Jul 14 '18 20:07 Coop920

This works fine for me in every browser but Firefox, where I'm having this issue. Slider width is calculated as a bajillion pixels (technical term) wide.

amberweinberg avatar Jul 26 '18 23:07 amberweinberg

I had this issue as well, to resolve it I had to apply a fixed width to the Slick container, rather than allowing the grid layout to automatically size it horizontally.

apcro avatar Aug 15 '18 12:08 apcro

Same issue here!

samuel-clara avatar Sep 17 '18 10:09 samuel-clara

Its failing for me in Chrome 69... Haven't checked other browsers yet...

mikkelwf avatar Sep 19 '18 07:09 mikkelwf

@Coop920 I had the same layout and adding overflow: hidden; to the grid item containing the slick slider fixed this for me as found here: #3415

Hopefully this helps some people with the same issue while we wait for a fix!

JJGerrish avatar Sep 19 '18 15:09 JJGerrish

Setting minmax(0, 1fr) or overflow: hidden; didn't fix it for me... What did the trick was to trigger a window resize in the slider's init callback so slick recalculate's the correct width.

var $featuredNewsItemsList = $(this).find('.js-c-news-items__list');
$featuredNewsItemsList.on('init', function(event, slick, currentSlide, nextSlide) { 
     $(window).trigger('resize');
});
$featuredNewsItemsList.slick({
     //settings
});

mdominguez avatar Sep 22 '18 17:09 mdominguez

Bumping this issue is still a thing in 2019

rdeeb avatar Jan 09 '19 14:01 rdeeb

Проблема может быть и когда родитель не имеет свойства flex, какой нибудь даже дальний родитель гораздо выше по вложенности. На самом деле display: flex не мешает слайдеру, мешает именно flex-grow: 1; или grid-template: 1fr 1fr; даже если эти свойства стоят гораздо выше по вложенности, например на body. Слайдер берет ширину не там где flexbox или grid layout ее динамически просчитывают. Проблему можно решить только если написать новый слайдер, так как автор данный слайдер уже не поддерживает, а жаль...

KimonoVIP avatar Feb 28 '19 11:02 KimonoVIP

In case it helps someone, I put this codepen together as a proof of concept for a slider we need to implement. https://codepen.io/anon/pen/RdVJPx

Here's the design: screen shot 2019-03-08 at 7 11 37 pm

sjcallender avatar Mar 08 '19 14:03 sjcallender

In case it helps someone, I put this codepen together as a proof of concept for a slider we need to implement. https://codepen.io/anon/pen/RdVJPx

Here's the design:

Oh my. Too many js for a simple grid and a simple slider. This is a terrible crutch, but a worker. Probably not dragging him into my project. It's easier for me to set the width in the grid in percent, then it works fine

KimonoVIP avatar Mar 14 '19 12:03 KimonoVIP

See #3415, this issue is not related to Slick, it's the expected behavior of fr units. Use minmax(0, 1fr); to allow your grid items to shrink.

enguerranws avatar Mar 27 '19 06:03 enguerranws

See #3415, this issue is not related to Slick, it's the expected behavior of fr units. Use minmax(0, 1fr); to allow your grid items to shrink. Thanks^ it's work!) Need this write in documentation)

KimonoVIP avatar Mar 27 '19 11:03 KimonoVIP

@enguerranws

See #3415, this issue is not related to Slick, it's the expected behavior of fr units. Use minmax(0, 1fr); to allow your grid items to shrink.

This trick does not help for height if the slider is vertical. grid-template-rows: minmax (0, 1fr); also tried (

KimonoVIP avatar Mar 27 '19 15:03 KimonoVIP

You mean, slick.js is in { vertical: true, verticalSwipe: true }? See: https://codepen.io/enguerranws/pen/dLNGQE

enguerranws avatar Apr 09 '19 12:04 enguerranws

There seems to have been a change in Chrome 80 so this now applies in more cases than it did previously.

BenSpace48 avatar Feb 12 '20 15:02 BenSpace48

There seems to have been a change in Chrome 80 so this now applies in more cases than it did previously.

yes, after one of the latest updates even if one of parent containers has fixed width it not helps. Required to be not "fr" width of column

mrTyson avatar Feb 12 '20 17:02 mrTyson

Use minmax(0, 1fr); to allow your grid items to shrink.

Worked great for me! 🎉

gruffvaughan avatar Sep 01 '20 10:09 gruffvaughan

See #3415, this issue is not related to Slick, it's the expected behavior of fr units. Use minmax(0, 1fr); to allow your grid items to shrink.

Worked great for me.

amingarro avatar Aug 20 '21 22:08 amingarro

in case of auto this also works: grid-template-columns: minmax(0, auto) 200px;

skrbnv avatar Nov 13 '22 12:11 skrbnv

best solved: grid-template-columns: calc(100% - 200px) 200px;

crawlynoob avatar Jul 24 '23 12:07 crawlynoob