vue-slick-carousel icon indicating copy to clipboard operation
vue-slick-carousel copied to clipboard

Inline style of slides are been removed

Open dieterc opened this issue 5 years ago • 8 comments

When the slider is been loaded, all the inline styles for each slide are been removed. I need the inline styling because I set the background image dynamically. I checked if all the attributes are being removed and that is not the case.

A dirty workaround now is to add a data attribute with the inline styles and when the slider is loaded copy that to the styles attribute.

But why are the styles beene removed in the first place?

dieterc avatar Mar 09 '20 11:03 dieterc

I have this problem too, It just takes all the styles I set to the div and throw them away, this was not how the original slick js did it. I have a version in raw js but It's just bad with this package

seunafara avatar May 18 '20 17:05 seunafara

No info/updates on this?

rshelnutt avatar Nov 14 '20 04:11 rshelnutt

I have the same problem with slider. If page run first time - all are ok. When navigating through pages in SPA all styles are removing from slide. Someone did solved this?

Seeman13 avatar Jan 31 '21 17:01 Seeman13

Similar problem here too. Argh!!!

victorighalo avatar Mar 16 '21 12:03 victorighalo

You can avoid this using :style="'...'" instead of style="..." I don't know how, but it works...

ErriourMe avatar Mar 24 '21 18:03 ErriourMe

Hi guys the simple way to fix this is like so:

< div class="slider-wrapper">

< VueSlickCarousel v-bind="slickOptions" >

< div class=“box” >1< /div >
< div class=“box” >2< /div >
< div class=“box”>3< /div >

</ VueSlickCarousel >

</ div>

.slider-wrapper {
  width: -webkit-fill-available;
  width: -moz-available;
  width: 100%;
  overflow: hidden;
}

seunafara avatar Mar 24 '21 18:03 seunafara

I forgot to add that properties of classes of elements within the VueSlickCarousel that’s being overwritten should be marked with !important . The above answer was to make sure the slider works and stays in place.

e.g


.box {
 width: 90% !important;
 }

seunafara avatar Mar 25 '21 09:03 seunafara

The primary issue/concern here is that this happens to begin with. While there may be workarounds, those come with a host of their own problems.

@seunafara Important flags on CSS, especially with dynamic components is very bad practice (for good reason). It's a last resort and is usually only needed (rather, should only be needed) in very niche circumstances. While this may work for some in the meantime, it should not be considered a globally acceptable solution.

@ErriourRU Using :style attribute just bypasses VSC's apparent programatic removal of inline styles; this attribute type is specific to Vue, which compiles it afterwards in proper format before displaying. Depending where VCS's style removal occurs during the lifecycle, it may (and sometimes may not) also remove styles applied via :style. In my instance, it was still stripped completely.

rshelnutt avatar Mar 26 '21 15:03 rshelnutt