I'm using Swiper Element (WebComponent) and I'm trying to adjust the styles of each slide. I'm using injectStyles
for this purpose, which works fine for most parts:
export const PROJECT_SWIPER_OPTIONS: SwiperOptions = {
direction: 'horizontal',
loop: false,
grabCursor: true,
navigation: true,
injectStyles: [`
:host {
height: 100%;
}
:host .swiper-wrapper {
border: 1px solid red;
}
:host .swiper-slide {
border: 1px solid green;
}
`],
};
The styles for :host
and :host .swiper-wrapper
are applied correctly. Unfortunately the styles for :host .swiper-slide
are ignored. I also tried :host .slide
, :host swiper-slide
but it won't work either.
It seems that the styles aren't applied since the <swiper-slide>
elements are slotted into the shadow element.
Any idea how to style the elements?
Currently I'm using this in my Angular project:
:host ::ng-deep {
swiper-slide {
border: 1px solid green;
}
}
Which works, but I do have styles in the Swiper config and the componentn SCSS now. This doesn't seem right.
swiper-slide
-element like shown in the question. The:host ::ng-deep { }
-selector can be omitted and is Angular specific. So it should work in React also. – Grubstake