I have created a carousel using Swiper JS, however my box-shadow
seems to be cut off due to the overflow: hidden;
property which applied on the .swiper
class (I'm assuming the properties are applied through the Swiper Object Initialization).
How can I fix this?
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'horizontal',
loop: false,
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// Responsive breakpoints
breakpoints: {
600: {
slidesPerView: 3,
spaceBetween: 15
}
}
});
.product-block {
background: #ffffff;
border-radius: 4px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgb(51, 51, 51) 0px 0px 0px 3px;
}
.product-img img {
max-width: 100%;
height: auto;
aspect-ratio: 4 / 3.5;
}
.product-description {
padding: 7px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgb(51, 51, 51) 0px 0px 0px 3px;
}
.product-description h2,
h3,
h4 {
font-size: 0.8rem;
font-weight: 500;
letter-spacing: 0.3px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
<link rel="stylesheet" href="@8/swiper-bundle.min.css">
<script src="@8/swiper-bundle.min.js"></script>
<div class="swiper">
<div class="home-wrapper-categories swiper-wrapper">
<article class="product-block swiper-slide">
<header class="product-img">
<img src=".2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide">
<header class="product-img">
<img src=".2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide drop-shadow">
<header class="product-img">
<img src=".2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
I have created a carousel using Swiper JS, however my box-shadow
seems to be cut off due to the overflow: hidden;
property which applied on the .swiper
class (I'm assuming the properties are applied through the Swiper Object Initialization).
How can I fix this?
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'horizontal',
loop: false,
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// Responsive breakpoints
breakpoints: {
600: {
slidesPerView: 3,
spaceBetween: 15
}
}
});
.product-block {
background: #ffffff;
border-radius: 4px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgb(51, 51, 51) 0px 0px 0px 3px;
}
.product-img img {
max-width: 100%;
height: auto;
aspect-ratio: 4 / 3.5;
}
.product-description {
padding: 7px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgb(51, 51, 51) 0px 0px 0px 3px;
}
.product-description h2,
h3,
h4 {
font-size: 0.8rem;
font-weight: 500;
letter-spacing: 0.3px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
<link rel="stylesheet" href="https://cdn.jsdelivr/npm/swiper@8/swiper-bundle.min.css">
<script src="https://cdn.jsdelivr/npm/swiper@8/swiper-bundle.min.js"></script>
<div class="swiper">
<div class="home-wrapper-categories swiper-wrapper">
<article class="product-block swiper-slide">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide drop-shadow">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
Share
Improve this question
edited Aug 12, 2022 at 13:10
Parit Sawjani
asked Aug 12, 2022 at 12:41
Parit SawjaniParit Sawjani
9081 gold badge13 silver badges29 bronze badges
3 Answers
Reset to default 12I figured it out. I added a some padding-bottom
to my .swiper
class and the box-shadow
became more visible. This also works for the left, right and top padding since the overflow: hidden
is also applied on those areas too.
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'horizontal',
loop: false,
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// Responsive breakpoints
breakpoints: {
600: {
slidesPerView: 3,
spaceBetween: 15
}
}
});
.swiper {
padding: 10px 10px 10px 10px !important;
}
.product-block {
background: #ffffff;
border-radius: 4px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgb(51, 51, 51) 0px 0px 0px 3px;
}
.product-img img {
max-width: 100%;
height: auto;
aspect-ratio: 4 / 3.5;
}
.product-description {
padding: 7px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgb(51, 51, 51) 0px 0px 0px 3px;
}
.product-description h2,
h3,
h4 {
font-size: 0.8rem;
font-weight: 500;
letter-spacing: 0.3px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
<link rel="stylesheet" href="https://cdn.jsdelivr/npm/swiper@8/swiper-bundle.min.css">
<script src="https://cdn.jsdelivr/npm/swiper@8/swiper-bundle.min.js"></script>
<div class="swiper">
<div class="home-wrapper-categories swiper-wrapper">
<article class="product-block swiper-slide">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide drop-shadow">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
<article class="product-block swiper-slide drop-shadow">
<header class="product-img">
<img src="https://images.unsplash./photo-1578985545062-69928b1d9587?ixlib=rb-1.2.1&w=1080&fit=max&q=80&fm=jpg&crop=entropy&cs=tinysrgb" alt="">
</header>
<footer class="product-description">
<h2>Fudge cake</h2>
</footer>
</article>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
I ran into a similar problem where a card's box shadow keeps getting cut off (hidden behind another card). I use SCSS for
loop to increment the z-index
for every slide to solve it as follows:
// box shadow effect on every slide
& .swiper-slide {
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.7);
-webkit-box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.7);
-moz-box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.7);
}
// increment z-index for each slide
@for $i from 1 to 10 {
& .swiper-slide:nth-child(#{$i}):hover {
z-index: $i;
}
}
My solution (LESS) when you have just 1 slide per view:
.swiper{
overflow: visible;
.swiper-slide.swiper-slide-prev,.swiper-slide.swiper-slide-next{
opacity: 0;
transition: opacity 200ms linear;
}
.swiper-slide-active{
padding: 1rem;
margin: -1rem;
}
}