Responsive Slider Fix
May 7, 2025 ยท AI Conversations
<script>
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
new Swiper('.industries-slider', {
// slidesPerView: 4,
spaceBetween: 30,
navigation: {
nextEl: '.industries-button-next',
prevEl: '.industries-button-prev',
},
loop: true,
breakpoints: {
0: { slidesPerView: 1 },
768: { slidesPerView: 2 },
1200: { slidesPerView: 3 },
1366: { slidesPerView: 4 }
}
});
});
</script>
<style>
.industries-slider-wrapper {
padding: 0;
position: relative;
}
.industries-slider {
padding-bottom: 130px;
}
.industries-slide-image {
width: 100%;
height: auto;
border-radius: 6px;
}
.industries-button {
position: absolute;
bottom: 18px;
left: 0;
background: #fff;
color: #000;
padding: 28px 33px 27px 16px;
border-radius: 0 50px 50px 0;
font-size: 20px;
font-weight: 500;
min-width: 90%;
overflow: hidden;
z-index: 1;
transition: color 0.3s ease;
}
.industries-button::before {
content: '';
position: absolute;
bottom: 0;
left: 16px;
width: 50px;
height: 4px;
background: #f13d68;
border-radius: 0 50px 50px 0;
transition: all 0.4s ease;
z-index: 0;
}
.industries-slide:hover .industries-button::before {
width: 100%;
height: 100%;
border-radius: 0 50px 50px 0;
left: 0px;
}
.industries-slide:hover .industries-button {
color: #fff;
}
.industries-button span {
position: relative;
z-index: 2;
}
.industries-slider-navigation {
position: absolute;
bottom: 32px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 20px;
}
.custom-arrow {
background: transparent;
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
padding: 0;
border: none;
}
.custom-arrow svg {
display: block;
}
@media (max-width: 1024px) {
.industries-button {
font-size: 16px;
padding: 20px 24px 20px 12px;
min-width: 80%;
}
.industries-slider {
padding-bottom: 100px;
}
.industries-slider-navigation {
bottom: 20px;
gap: 10px;
}
.custom-arrow svg {
width: 32px;
height: 32px;
}
}
</style>
### ๐ง Issues
1. **Button overflow or fixed width** on smaller screens.
2. **Absolute positioning** of button inside slide may not adjust on narrow screens.
3. Navigation (`.industries-slider-navigation`) is not optimized for small screens.
4. Swiper slide visibility (breakpoints) is good but you can fine-tune spacing if needed.
—
### โ Add or Update CSS in the “ block at the bottom:
@media (max-width: 1199px) {
.industries-button {
font-size: 14px;
padding: 14px 16px 14px 12px;
min-width: 100%;
bottom: 12px;
border-radius: 0 30px 30px 0;
}
.industries-button::before {
height: 3px;
left: 12px;
}
.industries-slide:hover .industries-button::before {
border-radius: 0 30px 30px 0;
}
.industries-slider-navigation {
bottom: 12px;
gap: 8px;
}
.custom-arrow svg {
width: 28px;
height: 28px;
}
}
@media (max-width: 767px) {
.industries-button {
font-size: 12px;
padding: 12px 14px 12px 10px;
min-width: 100%;
bottom: 10px;
}
.industries-button::before {
height: 2px;
left: 10px;
}
.industries-slider {
padding-bottom: 80px;
}
.industries-slider-navigation {
bottom: 8px;
}
}
—
### โ
Optional JS (Already good):
Swiper breakpoints are fine:
breakpoints: {
0: { slidesPerView: 1 },
768: { slidesPerView: 2 },
1200: { slidesPerView: 3 },
1366: { slidesPerView: 4 }
}
—
This fix adjusts the button size, spacing, and positioning for screen widths **below 1200px** โ including tablets and phones โ **without changing anything for desktop**.
Would you like me to also tighten space between slides for small devices?
<script>
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
new Swiper('.industries-slider', {
// slidesPerView: 4,
spaceBetween: 30,
navigation: {
nextEl: '.industries-button-next',
prevEl: '.industries-button-prev',
},
loop: true,
breakpoints: {
0: { slidesPerView: 1 },
768: { slidesPerView: 2 },
1200: { slidesPerView: 3 },
1366: { slidesPerView: 4 }
}
});
});
</script>
<style>
.industies-section{
max-width:100%;
overflow:hidden ;
}
.industries-slider-wrapper {
padding: 0;
position: relative;
}
.industries-slider {
padding-bottom: 130px;
}
.industries-slide-image {
width: 100%;
height: auto;
border-radius: 6px;
}
.industries-button {
position: absolute;
bottom: 18px;
left: 0;
background: #fff;
color: #000;
padding: 28px 33px 27px 16px;
border-radius: 0 50px 50px 0;
font-size: 20px;
font-weight: 500;
min-width: 90%;
overflow: hidden;
z-index: 1;
transition: color 0.3s ease;
}
.industries-button::before {
content: '';
position: absolute;
bottom: 0;
left: 16px;
width: 50px;
height: 4px;
background: #f13d68;
border-radius: 0 50px 50px 0;
transition: all 0.4s ease;
z-index: 0;
}
.industries-slide:hover .industries-button::before {
width: 100%;
height: 100%;
border-radius: 0 50px 50px 0;
left: 0px;
}
.industries-slide:hover .industries-button {
color: #fff;
}
.industries-button span {
position: relative;
z-index: 2;
}
.industries-slider-navigation {
position: absolute;
bottom: 32px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 20px;
}
.custom-arrow {
background: transparent;
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
padding: 0;
border: none;
}
.custom-arrow svg {
display: block;
}
@media (max-width: 1024px) {
.industries-button {
font-size: 16px;
padding: 20px 24px 20px 12px;
min-width: 80%;
}
.industries-slider {
padding-bottom: 100px;
}
.industries-slider-navigation {
bottom: 20px;
gap: 10px;
}
.custom-arrow svg {
width: 32px;
height: 32px;
}
}
@media (max-width: 1199px) {
.industries-button {
font-size: 14px;
padding: 14px 16px 14px 12px;
min-width: 100%;
bottom: 12px;
border-radius: 0 30px 30px 0;
}
.industries-button::before {
height: 3px;
left: 12px;
}
.industries-slide:hover .industries-button::before {
border-radius: 0 30px 30px 0;
}
.industries-slider-navigation {
bottom: 12px;
gap: 8px;
}
.custom-arrow svg {
width: 28px;
height: 28px;
}
}
@media (max-width: 767px) {
.industries-button {
font-size: 12px;
padding: 12px 14px 12px 10px;
min-width: 100%;
bottom: 10px;
}
.industries-button::before {
height: 2px;
left: 10px;
}
.industries-slider {
padding-bottom: 80px;
}
.industries-slider-navigation {
bottom: 8px;
}
.industries-slide{
width: 100% !important;
}
}
</style>
—
### โ
FIX: Add `object-fit: cover` and a `max-height` for mobile
Update your `.industries-slide-image` style and **add a mobile-specific override**:
### โ Update your CSS block like this:
.industries-slide-image {
width: 100%;
height: auto;
border-radius: 6px;
display: block;
object-fit: cover;
}
/* ๐ฝ Add this to control image height on smaller screens */
@media (max-width: 1199px) {
.industries-slide-image {
max-height: 300px;
height: auto;
}
}
@media (max-width: 767px) {
.industries-slide-image {
max-height: 220px;
height: auto;
}
}
—
### ๐ ๏ธ Why this works:
– `object-fit: cover` ensures the image fills the container without distortion.
– `max-height` keeps images from stretching too tall on narrow screens.
– This still allows full responsiveness without forcing fixed sizes.
Let me know if you want the height to be uniform regardless of image size (like a fixed container layout).