$(window).on({
load: function(){
$(this).trigger('resize');
}
});
$(document).ready(function(){
$('ul.tabs li').click(function(){
var tab_id = $(this).attr('data-tab');
$('ul.tabs li').removeClass('current');
$('.tab-content').removeClass('current');
$(this).addClass('current');
$("#"+tab_id).addClass('current');
})
})
var _prev = document.querySelector(".thumb-prev");
var _next = document.querySelector(".thumb-next");
var thumbnail;
var big;
thumbnail = new Swiper(".thumb", {
observer: true,
observeParents: true,
watchSlidesVisibility: true,
watchSlidesProgress: true,
centeredSlides: false,
slidesPerView: 3,
spaceBetween: 2,
loop: true,
direction: "vertical",
slideToClickedSlide: true,
rebuildOnUpdate: true
});
big = new Swiper(".big", {
observer: true,
observeParents: true,
watchSlidesVisibility: true,
watchSlidesProgress: true,
loop: true,
slidesPerView: 3,
navigation: {
nextEl: _next,
prevEl: _prev,
},
autoplay: {
delay: 1500,
disableOnInteraction: false,
pauseOnMouseEnter: false,
},
rebuildOnUpdate: true
});
big.controller.control = thumbnail;
thumbnail.controller.control = big;
big.update();
var _prev = document.querySelector(".thumb-prev2");
var _next = document.querySelector(".thumb-next2");
var thumbnail2;
var big2;
thumbnail2 = new Swiper(".thumb2", {
observer: true,
observeParents: true,
watchSlidesVisibility: true,
watchSlidesProgress: true,
centeredSlides: false,
slidesPerView: 3,
spaceBetween: 2,
loop: true,
direction: "vertical",
slideToClickedSlide: true,
rebuildOnUpdate: true
});
big2 = new Swiper(".big2", {
observer: true,
observeParents: true,
loop: true,
watchSlidesVisibility: true,
watchSlidesProgress: true,
slidesPerView: 3,
navigation: {
nextEl: _next,
prevEl: _prev,
},
autoplay: {
delay: 1500,
disableOnInteraction: false,
pauseOnMouseEnter: false,
},
rebuildOnUpdate: true
});
big2.controller.control = thumbnail2;
thumbnail2.controller.control = big2;
big2.update();
#import url('https://fonts.googleapis.com/css2?family=Roboto+Slab:wght#100;200;300;400;500;600;700;800;900&display=swap');
.roboto-slab {font-family: 'Roboto Slab', serif;}
.container {
font-family: 'Roboto Slab', serif;
}
/* tab area */
ul.tabs{
margin: 0px;
padding: 0px;
list-style: none;
}
ul.tabs li{
background: none;
color: #222;
display: inline-block;
padding: 10px 15px;
cursor: pointer;
}
ul.tabs li.current{
background: #ededed;
color: #222;
}
.tab-content{
display: none;
padding: 15px 0;
border-top:3px solid #eee;
}
.tab-content.current{
display: inherit;
}
/* //tab area */
body, html {
margin: 0;
padding: 0;
}
.swiper-initialized {
overflow: hidden;
}
.swiper-slide-active {
color: blue !important; /* paired item style */
}
.swiper-slide-thumb-active {
color: greenyellow; /* same as paired item style, but it works when using 'thumbs:...' settings. It's NOT used here */
}
.slider__area {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 60vw;
}
.slider__box {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.big {
display: flex;
justify-content: center;
align-items: center;
width: 50vw;
height: 30vw;
background-color: aquamarine;
}
.big2 {
display: flex;
justify-content: center;
align-items: center;
width: 50vw;
height: 30vw;
background-color:skyblue;
}
.swiper-slide {
display: flex;
justify-content: center;
align-items: center;
font-size: 50px;
font-weight: 600;
color: yellow;
}
.swiper-slide:hover {
background-color: hotpink;
cursor: pointer;
}
.thumb {
width: 20vw;
max-height: 30vh;
background-color: darkorange;
}
.thumb .swiper-slide {
background: crimson;
display: flex;
align-items: center;
cursor: pointer;
}
.thumb .swiper-slide:hover {
background: mediumturquoise;
}
.thumb2 {
width: 20vw;
max-height: 30vh;
background-color: mediumslateblue;
}
.thumb2 .swiper-slide {
background: coral;
display: flex;
align-items: center;
cursor: pointer;
}
.thumb2 .swiper-slide:hover {
background: mediumseagreen;
}
.slider__arrowbox {
position: absolute;
display: flex;
justify-content: space-around;
align-items: center;
width: 20vw;
height: 5vw;
background-color: midnightblue;
top: -7vw;
right: 0vw;
}
.slider__arrowbox .swiper-button-prev {
position: relative;
padding: 0.5vw 2vw;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin-top: 0;
margin-bottom: 0;
color:lime;
}
.slider__arrowbox .swiper-button-next {
position: relative;
padding: 0.5vw 2vw;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin-top: 0;
margin-bottom: 0;
color:lime;
}
.slider__arrowbox .swiper-button-prev:hover,
.slider__arrowbox .swiper-button-next:hover {
color: blue;
background-color: aliceblue;
}
.slider__arrowbox .swiper-button-prev2 {
position: relative;
padding: 0.5vw 2vw;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin-top: 0;
margin-bottom: 0;
color:lime;
}
.slider__arrowbox .swiper-button-next2 {
position: relative;
padding: 0.5vw 2vw;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin-top: 0;
margin-bottom: 0;
color:lime;
}
.slider__arrowbox .swiper-button-prev2:hover,
.slider__arrowbox .swiper-button-next2:hover {
color: blue;
background-color: aliceblue;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/8.2.6/swiper-bundle.min.css" rel="stylesheet"/>
<div class="container">
<ul class="tabs">
<li class="tab-link current" data-tab="tab-1">First Item</li>
<li class="tab-link" data-tab="tab-2">Second Item</li>
</ul>
<div id="tab-1" class="tab-content current">
<div class="slider__area">
<div class="slider__box">
<div class="thumb swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
# 01
</div>
<div class="swiper-slide">
# 02
</div>
<div class="swiper-slide">
# 03
</div>
<div class="swiper-slide">
# 04
</div>
<div class="swiper-slide">
# 05
</div>
<div class="swiper-slide">
# 06
</div>
<div class="swiper-slide">
# 07
</div>
<div class="swiper-slide">
# 08
</div>
</div>
</div>
<div class="big swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
#01
</div>
<div class="swiper-slide">
#02
</div>
<div class="swiper-slide">
#03
</div>
<div class="swiper-slide">
#04
</div>
<div class="swiper-slide">
#05
</div>
<div class="swiper-slide">
#06
</div>
<div class="swiper-slide">
#07
</div>
<div class="swiper-slide">
#08
</div>
</div>
</div>
<div class="slider__arrowbox">
<div class="swiper-button-prev thumb-prev"></div>
<div class="swiper-button-next thumb-next"></div>
</div>
</div>
</div>
</div>
<div id="tab-2" class="tab-content">
<div class="slider__area">
<div class="slider__box">
<div class="thumb2 swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
# 01
</div>
<div class="swiper-slide">
# 02
</div>
<div class="swiper-slide">
# 03
</div>
<div class="swiper-slide">
# 04
</div>
<div class="swiper-slide">
# 05
</div>
<div class="swiper-slide">
# 06
</div>
<div class="swiper-slide">
# 07
</div>
<div class="swiper-slide">
# 08
</div>
</div>
</div>
<div class="big2 swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
#01
</div>
<div class="swiper-slide">
#02
</div>
<div class="swiper-slide">
#03
</div>
<div class="swiper-slide">
#04
</div>
<div class="swiper-slide">
#05
</div>
<div class="swiper-slide">
#06
</div>
<div class="swiper-slide">
#07
</div>
<div class="swiper-slide">
#08
</div>
</div>
</div>
<div class="slider__arrowbox">
<div class="swiper-button-prev thumb-prev2"></div>
<div class="swiper-button-next thumb-next2"></div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/8.2.6/swiper-bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
[demo check in codepen][1]
I'm tryting to make swiper slide in the tab.
Problem is if I clicked the second button is fine but after click again 1st menu and 2nd menu, slider is stopping. after that I click the thumbnail then move again.
I already add observer parameter but it doesn't work.
[https://codepen.io/patcaulfield/pen/xxjLxLm][1]
Related
Im trying to combine Swiper and Bootstrap; trying to make each item in a Bootstrap grid have a paginator for some text. The issue I'm having is that the columns are for some reason all taking 100% width.
Using bootstrap 5
var swiper = new Swiper(".swiper1", {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
var swiper = new Swiper(".swiper2", {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
var swiper = new Swiper(".swiper3", {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
.past-projects {
margin-top: 100px;
}
.past-projects h1 {
margin-bottom: 20px !important;
}
.past-projects .row .project {
width: 300px;
}
.past-projects .row .project img {
width: 100%;
height: 60%;
border-radius: 8px;
border: 3px solid #4b4b4b;
}
.past-projects .row .project .text {
text-align: center;
margin-top: 3px;
width: 100%;
display: block;
color: white;
}
.discord {
margin-top: 50px;
color: white;
text-align: center;
}
.discord a {
margin-top: 20px !important;
margin-right: 10px !important;
}
.swiper {
width: 100%;
height: 100%;
}
.swiper-slide {
color: white;
text-align: center;
font-size: 18px;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.swiper-slide img {
display: block;
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
}
.swiper {
margin-left: auto;
margin-right: auto;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="bg-dark">
<div class="past-projects">
<h1 class="ps-1 text-white mx-auto text-center">Past Projects</h1>
<div class="row g-4">
<div class="col">
<div class="project mx-auto">
<img src="https://media.istockphoto.com/vectors/thumbnail-image-vector-graphic-vector-id1147544807?k=20&m=1147544807&s=612x612&w=0&h=pBhz1dkwsCMq37Udtp9sfxbjaMl27JUapoyYpQm0anc=" alt="">
<div class="text">
<p class="title">BloxRoyale</p>
<div class="swiper swiper1">
<div class="swiper-wrapper">
<p class="swiper-slide">ENG SLO GR</p>
<p class="swiper-slide">SP RU FP</p>
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
</div>
</div>
<div class="col">
<div class="project mx-auto">
<img src="https://media.istockphoto.com/vectors/thumbnail-image-vector-graphic-vector-id1147544807?k=20&m=1147544807&s=612x612&w=0&h=pBhz1dkwsCMq37Udtp9sfxbjaMl27JUapoyYpQm0anc=" alt="">
<div class="text">
<p class="title">BloxRoyale</p>
<div class="swiper swiper2">
<div class="swiper-wrapper">
<p class="swiper-slide">ENG SLO GR</p>
<p class="swiper-slide">SP RU FP</p>
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="project mx-auto">
<img src="https://media.istockphoto.com/vectors/thumbnail-image-vector-graphic-vector-id1147544807?k=20&m=1147544807&s=612x612&w=0&h=pBhz1dkwsCMq37Udtp9sfxbjaMl27JUapoyYpQm0anc=" alt="">
<div class="text">
<p class="title">BloxRoyale</p>
<div class="swiper swiper3">
<div class="swiper-wrapper">
<p class="swiper-slide">ENG SLO GR</p>
<p class="swiper-slide">SP RU FP</p>
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
var swiper = new Swiper(".mySwiper", {
loop: true,
spaceBetween:24,
grabCursor: true,
pagination: {
el: ".swiper-pagination",
dynamicBullets: true,
},
breakpoints: {
768: {
slidesPerView: 1,
},
1024: {
slidesPerView: 3,
spaceBetween: 48,
},
},
});
My issue:
I'm making somewhat of a Zillow clone. I need the page to not expand beyond 100% of the viewport height however, I'm making a section with the intentions of having the overflow property set to scroll. When I do this, the section expands beyond the viewport height and leaves a large whitespace at the bottom of my page. I can adjust the height to fill up to 100vh however, if I adjust the screen vertically the div with the scroll overflow doesn't adjust to the viewport height. Thanks for any and all help!
Here's a screenshot of my issue:
The circled section is the section that I need the overflow to scroll:
This is my HTML for the entire 'popup' portion:
<div class="home__popup--backdrop">
<div class="home__popup--container">
<div class="home__popup--left">
<div class="home__popup--img--container">
<div class="home__popup--img--main--container">
<img src="./src/img/home-0.jpg" alt="home-0" class="home__popup--img--main">
</div>
<div class="home__popup--img--sub--container">
<img src="./src/img/home-1.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-2.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-3.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-4.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-5.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-0.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-1.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-2.jpg" alt="home-0" class="home__popup--img--sub">
</div>
</div>
</div>
<div class="home__popup--right">
<div class="home__popup--header--container">
<div class="home__popup--logo--container">
<div class="logo__container--home">
<img src="./src/img/logo__house.svg" alt="logo-homes" class="logo logo__homes logo__homes--small">
</div>
<div class="logo__container--txt">
<img src="./src/img/logo__txt.svg" alt="logo-homes" class="logo logo__homes logo__txt--small">
</div>
</div>
<div class="home__popup--social--container">
<div class="home__popup--social">
<img src="./src/img/like.svg" alt="logo like" class="popup__logo logo__like">
<p>Save</p>
</div>
<div class="home__popup--share">
<div class="home__popup--social">
<img src="./src/img/next.svg" alt="logo next" class="popup__logo logo__next">
<p>Share</p>
</div>
</div>
<div class="home__popup--more">
<div class="home__popup--social">
<img src="./src/img/more.svg" alt="logo more" class="popup__logo logo__more">
<p>More</p>
</div>
</div>
</div>
</div>
<div class="home__popup--details--container">
<div class="home__popup--details">
<p class="home__popup--price">$500,000</p>
<p class="home__popup--beds home__popup--details--home">3 <span>bds</span></p>
<p class="home__popup--baths home__popup--details--home">2 <span>ba</span></p>
<p class="home__popup--sqft home__popup--details--home">2,245 <span>sqft</span></p>
</div>
<div class="home__popup--address--container">
<p class="home__popup--address">
4210 sharman rd<span>, </span>
</p>
<p class="home__popup--city">Madison<span>, </span></p>
<p class="home__popup--state">WI</p>
</div>
<div class="home__popup--btn--container">
<button class="btn__agent">Contact Agent</button>
</div>
</div>
<div class="home__popup--overview--container">
<div class="home__popup--overview--container--links">
<img src="./src/img/001-left-arrow.svg" alt="arrow-left" class = 'arrow-small arrow-small--left'>
<div class="home__popup--overview home__popup--overview--active home__popup--overview--container--links--text--container" data-list-section = 0>
<p class="home__popup--overview--text home__popup--overview--container--links--text">Overview</p>
</div>
<div class="home__popup--facts home__popup--overview--container--links--text--container">
<p class="home__popup--facts--text home__popup--overview--container--links--text">Facts and features</p>
</div>
<div class="home__popup--value home__popup--overview--container--links--text--container">
<p class="home__popup--value--text home__popup--overview--container--links--text">Home value</p>
</div>
<div class="home__popup--history home__popup--overview--container--links--text--container" data-list-section = 1>
<p class="home__popup--history--text home__popup--overview--container--links--text">Price and tax history</p>
</div>
<div class="home__popup--monthly home__popup--overview--container--links--text--container">
<p class="home__popup--monthly--text home__popup--overview--container--links--text">Monthly cost</p>
</div>
<div class="home__popup--rental home__popup--overview--container--links--text--container">
<p class="home__popup--rental--text home__popup--overview--container--links--text">Rental Value</p>
</div>
<div class="home__popup--schools home__popup--overview--container--links--text--container" data-list-section = 2>
<p class="home__popup--schools--text home__popup--overview--container--links--text">Nearby schools</p>
</div>
<div class="home__popup--similar home__popup--overview--container--links--text--container">
<p class="home__popup--similar--text home__popup--overview--container--links--text">Similar homes</p>
</div>
<div class="home__popup--neighborhood home__popup--overview--container--links--text--container">
<p class="home__popup--neighborhood--text home__popup--overview--container--links--text">Neighborhood</p>
</div>
<div class="home__popup--homes-for-you home__popup--overview--container--links--text--container">
<p class="home__popup--homes-for-you--text home__popup--overview--container--links--text">Homes for you</p>
</div>
<img src="./src/img/002-right-arrow.svg" alt="arrow-right" class = 'arrow-small arrow-small--right'>
</div>
<div class="home__popup--scroll">
<div class="home__popup--home--detail--container">
<div class="home__popup--map--container">
<div class="test" id = "home__popup--map"></div>
</div>
<div class="home__popup--text--container">
<div class="home__popup--text--stats">
<P class="home__popup--text--header">Overview</P>
<div class="home__popup--text--user-activity">
<p class="home__popup--text--time">Time on Home Finder  <span> --</span></p>
<p class="home__popup--text--views">Views <span>64</span></p>
<p class="home__popup--text--saves">Saves <span>1</span></p>
</div>
<p class="home__popup--text--description">
No showings until 8/22 OH.....
</p>
<p class="home__popup--text--read-more">Read more</p>
</div>
<p class="home__popup--text--open-house--header">Open House</p>
<p class="home__popup--text--open-house--day">Sun, Aug 22</p>
<p class="home__popup--text--open-house--time">12:00 PM - 2:00 PM</p>
<ul class="home__popup--text--agent--container">
<li class="home__popup--text--agent">Kavita Biyani</li>
<li class="home__popup--text--agent">Nik Tantardini</li>
<li class="home__popup--text--agent">First Weber INC</li>
<li class="home__popup--text--agent">Lena Oberwetter</li>
<li class="home__popup--text--agent">Prince Michael</li>
</ul>
<div class="home__popup--overview--text">
</div>
<div class="home--popup--overview--specs">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here's the HTML for the overflowed portion:
<div class="home__popup--scroll">
<div class="home__popup--home--detail--container">
<div class="home__popup--map--container">
<div class="test" id = "home__popup--map"></div>
</div>
<div class="home__popup--text--container">
<div class="home__popup--text--stats">
<P class="home__popup--text--header">Overview</P>
<div class="home__popup--text--user-activity">
<p class="home__popup--text--time">Time on Home Finder  <span> --</span></p>
<p class="home__popup--text--views">Views <span>64</span></p>
<p class="home__popup--text--saves">Saves <span>1</span></p>
</div>
<p class="home__popup--text--description">
No showings until 8/22 OH. Amazing opportunity ...
</p>
<p class="home__popup--text--read-more">Read more</p>
</div>
<p class="home__popup--text--open-house--header">Open House</p>
<p class="home__popup--text--open-house--day">Sun, Aug 22</p>
<p class="home__popup--text--open-house--time">12:00 PM - 2:00 PM</p>
<ul class="home__popup--text--agent--container">
<li class="home__popup--text--agent">Kavita Biyani</li>
<li class="home__popup--text--agent">Nik Tantardini</li>
<li class="home__popup--text--agent">First Weber INC</li>
<li class="home__popup--text--agent">Lena Oberwetter</li>
<li class="home__popup--text--agent">Prince Michael</li>
</ul>
<div class="home__popup--overview--text">
</div>
<div class="home--popup--overview--specs">
</div>
</div>
</div>
Here is the relevant css:
.home__popup {
&--home--detail--container {
}
&--text {
&--description{
font-size: 1.8rem;
font-weight: 300;
color: $color-grey-text;
line-height: 1.3;
}
&--user-activity{
display: flex;
margin-bottom: 2rem;
font-size: 1.4rem;
color: $color-grey-text;
& span{
color: black;
}
}
&--time{
margin-right: 2rem;
border-right: 1px solid $color-grey-medium;
& span{
font-weight: bold;
margin-right: 2rem;
}
}
&--saves{
margin-left: 2rem;
& span{
font-weight: bold;
}
}
&--views{
margin-right: 2rem;
border-right: 1px solid $color-grey-medium;
& span{
font-weight: bold;
margin-right: 2rem;
}
}
&--header {
font-size: 2rem;
font-weight: 700;
letter-spacing: 0.5px;
margin-bottom: 2rem;
}
&--container {
margin-top: 2rem;
display: flex;
flex-direction: column;
margin-left: 1rem;
}
}
&--btn {
&--container {
margin-top: 1rem;
margin-left: 1rem;
display: flex;
justify-content: space-between;
width: 100%;
position: relative;
}
}
&--address {
&--container {
display: flex;
font-weight: 300;
font-size: 1.6rem;
margin-left: 1rem;
margin-top: 1rem;
}
}
&--baths {
margin-left: 0.5rem;
}
&--beds {
margin-left: 2rem;
}
&--price {
margin-top: 3rem;
font-size: 2.5rem;
font-weight: 500;
margin-left: 1rem;
}
&--social {
cursor: pointer;
&--container {
display: flex;
align-items: center;
width: 45%;
justify-content: space-around;
}
}
&--backdrop {
width: 100vw;
height: 100vh;
z-index: 2999;
position: absolute;
top: 0;
left: 0;
backdrop-filter: blur(2px);
background-color: rgba(0, 0, 0, 0.671);
}
&--container {
position: absolute;
top: 0;
left: 50%;
height: 100vh;
width: 65vw;
background-color: white;
transform: translateX(-50%);
z-index: 3000;
backdrop-filter: blur(2px);
display: flex;
flex-direction: row;
}
&--left {
position: relative;
width: 60%;
overflow-y: scroll;
}
&--right {
width: 40%;
position: relative;
}
&--img {
&--main {
height: auto;
object-fit: cover;
width: 100%;
}
&--sub {
height: 25rem;
object-fit: cover;
width: 49.5%;
margin-bottom: 0.4rem;
&--container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
}
}
&--header {
&--container {
display: flex;
justify-content: space-between;
position: relative;
border-bottom: 1px solid #6060607a;
margin-left: 1rem;
margin-right: 1rem;
}
}
&--logo {
&--container {
display: flex;
transform: translateY(1rem);
}
&__homes {
&--small {
height: 6rem;
width: 7rem;
}
}
}
&--details {
display: flex;
align-items: flex-end;
&--container {
display: flex;
flex-direction: column;
position: relative;
}
&--home {
font-size: 1.6rem;
font-weight: 400;
& span {
border-right: 1px solid $color-grey-text;
padding-right: 0.5rem;
font-weight: 300;
}
}
}
&--sqft {
margin-left: 0.5rem;
& span {
border-right: none;
}
}
&--overview {
color: $color-primary;
border-bottom: 2px solid $color-primary;
&--container {
display: flex;
flex-direction: column;
position: relative;
&--links {
display: flex;
overflow-x: scroll;
font-size: 14px;
font-weight: 300;
height: 5rem;
align-items: center;
margin-top: 2rem;
border-top: 1px solid $color-grey-medium;
border-bottom: 1px solid $color-grey-medium;
margin-left: 0.5rem;
margin-right: 0.5rem;
&::-webkit-scrollbar {
display: none;
}
&--text {
margin-left: 1rem;
margin-right: 1rem;
width: max-content;
&--container {
cursor: pointer;
height: 100%;
display: flex;
align-items: center;
transition: .2s all;
&:hover {
color: $color-primary-light;
}
}
}
}
}
}
}
I was having way too many issues out of pure stubbornness of not wanting to change my css however, I finally gave in and refactored the section as a grid. I'm now able to get it to function properly. Here's what it looks like:
And here's the css for the grid-layout:
&--right {
width: 40%;
position: relative;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 5rem 20rem 5rem auto;
}
here's the CSS for the updated div containing the scroll bar:
&--scroll{
grid-column: 1/-1;
grid-row: 4/5;
overflow-y: scroll;
overflow-x: hidden;
}
$(document).ready(function() {
$('.btn_activite').click(function() {
$('#activite').addClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_gestion').click(function() {
$('#activite').removeClass('active');
$('#gestion').addClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_creation').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').addClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_contenu').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').addClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_quotidien').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').addClass('active');
$('#temps').removeClass('active');
});
$('.btn_temps').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').addClass('active');
});
});
#charset "UTF-8";
#import url("../webfonts/GothamBook/stylesheet.css");
body {
font-family: GothamBook;
color: #FEFEFE;
}
.flex-container {
DISPLAY: FLEX;
justify-content: space-between;
width: 100%;
color: #FFFFFF;
}
.item {
background-color: black;
width: 5%;
margin: 2px;
}
.item-activite {
background-color: black;
width: 15%;
margin: 2px;
text-align: center;
}
.item-gestion {
background-color: #4D4D4D;
width: 15%;
margin: 2px;
text-align: center;
}
.item-creation {
background-color: #40A9F5;
width: 15%;
margin: 2px;
text-align: center;
}
.item-cont {
background-color: #362984;
width: 15%;
margin: 2px;
text-align: center;
}
.item-quot {
background-color: #662D91;
width: 15%;
margin: 2px;
text-align: center;
}
.item-temps {
background-color: #42A246;
width: 15%;
margin: 2px;
text-align: center;
}
.font-black {
color: #000000;
}
.font-grn {
color: #42A246;
}
.container {
display: flex;
justify-content: center;
align-content: center;
}
#activite, #gestion, #creation, #contenu, #quotidien, #temps {
display: none;
}
#activite.active ,#gestion.active , #creation.active ,#contenu.active ,#quotidien.active , #temps.active{
display: block;
}
a {
text-decoration: none;
color: #FFFFFF;
}
.btn_activite, .btn_gestion, .btn_creation, .btn_contenu, .btn_quotidien, .btn_temps {
transition: .2s ease;
-webkit-transition: .2s ease;
cursor: pointer;
}
.btn_activite:hover, .btn_gestion:hover, .btn_creation:hover , .btn_contenu:hover, .btn_quotidien:hover, .btn_temps:hover{
transform: scale(1.1);
-webkit-transform: scale(1.1);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Menu ACCES CBR -->
<div class="flex-container">
<div class="item">
</div>
<div class="item-activite">
<a class="btn_activite" href="#" >
Activité Assurance Q+
</a>
</div>
<div class="item-gestion">
<a href="#" class="btn_gestion">
Gestion Assurance Q+
</a>
</div>
<div class="item-creation">
<a class="btn_creation" href="#" >
Recherche - création
</a>
</div>
<div class="item-cont">
<a href="#" class="btn_contenu">
Recherche - Contenu
</a>
</div>
<div class="item-quot">
<a class="btn_quotidien" href="#">
Quotidien | Hebdo +
</a>
</div>
<div class="item-temps">
<a href="#" class="btn_temps">
Temps | Chrono
</a>
</div>
<div class="item">
</div>
</div>
<!-- Page Activite -->
<div class="container active" id="activite">
<h1>
Activité Assurance Q+
</h1>
</div>
<div class="container" id="gestion">
<h1>
Gestion Assurance Q+
</h1>
</div>
<!-- Page Recherche creation -->
<div class="container" id="creation">
<h1>
Recherche Creation
</h1>
</div>
<!-- Page Aventuriers -->
<div class="container" id="contenu">
<h1>
Recherche Contenu
</h1>
</div>
<!-- Page Équipiers -->
<div class="container" id="quotidien">
<h1>
Quotidien | Hebdo +
</h1>
</div>
<!-- Page Supporters -->
<div class="container" id="temps">
<h1>
Temps | Chrono
</h1>
</div>
This is a top menu with 6 elements each having 15% width. Ignore the div class="item" elements as they just fill the other 10% on each side of the menu.
What I want is to change the order of the 6 classes, so when I click on btn_creation, for example, this menu moves to position 2 (position 1 and 8 are fillers - class "item", I just use positions 2 to 7).
Hope it's clear?
Basically anything I click goes to position 2, moving the rest to the right.
p.s code not working properly in here, but in my computer it works... sorry first time I do this here.
I believe the runnable example below is what is trying to be achieved?
The only change is in the jQuery handling. All the current handling is commented-out, replaced by the short code snippet at the end of the document.ready function. See the comments there.
$(document).ready(function() {
/*
$('.btn_activite').click(function() {
$('#activite').addClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_gestion').click(function() {
$('#activite').removeClass('active');
$('#gestion').addClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_creation').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').addClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_contenu').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').addClass('active');
$('#quotidien').removeClass('active');
$('#temps').removeClass('active');
});
$('.btn_quotidien').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').addClass('active');
$('#temps').removeClass('active');
});
$('.btn_temps').click(function() {
$('#activite').removeClass('active');
$('#gestion').removeClass('active');
$('#creation').removeClass('active');
$('#contenu').removeClass('active');
$('#quotidien').removeClass('active');
$('#temps').addClass('active');
});
*/
// For any <a> tag class that starts with btn_
$('a[class^="btn_"]').click(function() {
// Get the parent div and move it after the
// first div. (with the item class)
$(this).parent().insertAfter($('.item')[0]);
});
});
#charset "UTF-8";
#import url("../webfonts/GothamBook/stylesheet.css");
body {
font-family: GothamBook;
color: #FEFEFE;
}
.flex-container {
DISPLAY: FLEX;
justify-content: space-between;
width: 100%;
color: #FFFFFF;
}
.item {
background-color: black;
width: 5%;
margin: 2px;
}
.item-activite {
background-color: black;
width: 15%;
margin: 2px;
text-align: center;
}
.item-gestion {
background-color: #4D4D4D;
width: 15%;
margin: 2px;
text-align: center;
}
.item-creation {
background-color: #40A9F5;
width: 15%;
margin: 2px;
text-align: center;
}
.item-cont {
background-color: #362984;
width: 15%;
margin: 2px;
text-align: center;
}
.item-quot {
background-color: #662D91;
width: 15%;
margin: 2px;
text-align: center;
}
.item-temps {
background-color: #42A246;
width: 15%;
margin: 2px;
text-align: center;
}
.font-black {
color: #000000;
}
.font-grn {
color: #42A246;
}
.container {
display: flex;
justify-content: center;
align-content: center;
}
#activite, #gestion, #creation, #contenu, #quotidien, #temps {
display: none;
}
#activite.active ,#gestion.active , #creation.active ,#contenu.active ,#quotidien.active , #temps.active{
display: block;
}
a {
text-decoration: none;
color: #FFFFFF;
}
.btn_activite, .btn_gestion, .btn_creation, .btn_contenu, .btn_quotidien, .btn_temps {
transition: .2s ease;
-webkit-transition: .2s ease;
cursor: pointer;
}
.btn_activite:hover, .btn_gestion:hover, .btn_creation:hover , .btn_contenu:hover, .btn_quotidien:hover, .btn_temps:hover{
transform: scale(1.1);
-webkit-transform: scale(1.1);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Menu ACCES CBR -->
<div class="flex-container">
<div class="item">
</div>
<div class="item-activite">
<a class="btn_activite" href="#" >
Activité Assurance Q+
</a>
</div>
<div class="item-gestion">
<a href="#" class="btn_gestion">
Gestion Assurance Q+
</a>
</div>
<div class="item-creation">
<a class="btn_creation" href="#" >
Recherche - création
</a>
</div>
<div class="item-cont">
<a href="#" class="btn_contenu">
Recherche - Contenu
</a>
</div>
<div class="item-quot">
<a class="btn_quotidien" href="#">
Quotidien | Hebdo +
</a>
</div>
<div class="item-temps">
<a href="#" class="btn_temps">
Temps | Chrono
</a>
</div>
<div class="item">
</div>
</div>
<!-- Page Activite -->
<div class="container active" id="activite">
<h1>
Activité Assurance Q+
</h1>
</div>
<div class="container" id="gestion">
<h1>
Gestion Assurance Q+
</h1>
</div>
<!-- Page Recherche creation -->
<div class="container" id="creation">
<h1>
Recherche Creation
</h1>
</div>
<!-- Page Aventuriers -->
<div class="container" id="contenu">
<h1>
Recherche Contenu
</h1>
</div>
<!-- Page Équipiers -->
<div class="container" id="quotidien">
<h1>
Quotidien | Hebdo +
</h1>
</div>
<!-- Page Supporters -->
<div class="container" id="temps">
<h1>
Temps | Chrono
</h1>
</div>
I suggest you to modify the name of id, that simplify all the code and use insertafter(): (here i have just add x_ in front of id names..
$(document).ready(function() {
var selector = $('a[class^=btn_]');
selector.on('click', function() {
let clasn = $(this).attr('class').split('_')[1];
$('div[id^=x_]').removeClass('active');
$('#x_' + clasn).addClass('active');
var move = $(this).closest('div');
move.insertAfter($('.item').first());
});
});
#charset "UTF-8";
#import url("../webfonts/GothamBook/stylesheet.css");
body {
font-family: GothamBook;
color: #FEFEFE;
}
.flex-container {
DISPLAY: FLEX;
justify-content: space-between;
width: 100%;
color: #FFFFFF;
}
.item {
background-color: black;
width: 5%;
margin: 2px;
}
.item-activite {
background-color: black;
width: 15%;
margin: 2px;
text-align: center;
}
.item-gestion {
background-color: #4D4D4D;
width: 15%;
margin: 2px;
text-align: center;
}
.item-creation {
background-color: #40A9F5;
width: 15%;
margin: 2px;
text-align: center;
}
.item-cont {
background-color: #362984;
width: 15%;
margin: 2px;
text-align: center;
}
.item-quot {
background-color: #662D91;
width: 15%;
margin: 2px;
text-align: center;
}
.item-temps {
background-color: #42A246;
width: 15%;
margin: 2px;
text-align: center;
}
.font-black {
color: #000000;
}
.font-grn {
color: #42A246;
}
.container {
display: flex;
justify-content: center;
align-content: center;
}
#x_activite,
#x_gestion,
#x_creation,
#x_contenu,
#x_quotidien,
#x_temps {
display: none;
}
#x_activite.active,
#x_gestion.active,
#x_creation.active,
#x_contenu.active,
#x_quotidien.active,
#x_temps.active {
display: block;
}
a {
text-decoration: none;
color: #FFFFFF;
}
.btn_activite,
.btn_gestion,
.btn_creation,
.btn_contenu,
.btn_quotidien,
.btn_temps {
transition: .2s ease;
-webkit-transition: .2s ease;
cursor: pointer;
}
.btn_activite:hover,
.btn_gestion:hover,
.btn_creation:hover,
.btn_contenu:hover,
.btn_quotidien:hover,
.btn_temps:hover {
transform: scale(1.1);
-webkit-transform: scale(1.1);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Menu ACCES CBR -->
<div class="flex-container">
<div class="item">
</div>
<div class="item-activite">
<a class="btn_activite" href="#">
Activité Assurance Q+
</a>
</div>
<div class="item-gestion">
<a href="#" class="btn_gestion">
Gestion Assurance Q+
</a>
</div>
<div class="item-creation">
<a class="btn_creation" href="#">
Recherche - création
</a>
</div>
<div class="item-cont">
<a href="#" class="btn_contenu">
Recherche - Contenu
</a>
</div>
<div class="item-quot">
<a class="btn_quotidien" href="#">
Quotidien | Hebdo +
</a>
</div>
<div class="item-temps">
<a href="#" class="btn_temps">
Temps | Chrono
</a>
</div>
<div class="item">
</div>
</div>
<!-- Page Activite -->
<div class="container active" id="x_activite">
<h1>
Activité Assurance Q+
</h1>
</div>
<div class="container" id="x_gestion">
<h1>
Gestion Assurance Q+
</h1>
</div>
<!-- Page Recherche creation -->
<div class="container" id="x_creation">
<h1>
Recherche Creation
</h1>
</div>
<!-- Page Aventuriers -->
<div class="container" id="x_contenu">
<h1>
Recherche Contenu
</h1>
</div>
<!-- Page Équipiers -->
<div class="container" id="x_quotidien">
<h1>
Quotidien | Hebdo +
</h1>
</div>
<!-- Page Supporters -->
<div class="container" id="x_temps">
<h1>
Temps | Chrono
</h1>
</div>
Can we make custom elements to have the same behavior as dots? What I want is to keep the default dots, but also have some other elements acting as dots. For example, if the slide 2 is active the element dot-2 should have the class active. The same goes for click behavior, if I'll click on the element .dot-3, the slide 3 should be active.
jsfiddle
<div id="carousel" class="slider">
<div class="slider-item">1</div>
<div class="slider-item">2</div>
<div class="slider-item">3</div>
</div>
<div class="extra-dots-box">
<div class="dot-1 extra-dot">
<span>1</span>
<h3>Custom Title</h3>
<p>lorem ipsum lorem ipsum</p>
</div>
<div class="dot-2 extra-dot">
<span>2</span>
<h3>Custom Title</h3>
<p>lorem ipsum lorem ipsum</p>
</div>
<div class="dot-3 extra-dot">
<span>3</span>
<h3>Custom Title</h3>
<p>lorem ipsum lorem ipsum</p>
</div>
</div>
css
.slider-item {
border: 5px solid #333;
background: #ccc;
height: 200px;
font-size: 72px;
text-align: center;
line-height: 200px;
}
/* Slider arrows */
.slick-arrow {
z-index: 9;
}
.slick-prev {
left: 0;
}
.slick-next {
right: 0;
}
/* extra dots */
.extra-dots-box{
display: flex;
margin-top: 100px;
margin-bottom: 100px;
}
.extra-dots-box .extra-dot{
width: 350px;
height: 250px;
background: #111111;
color: #ffffff;
font-size: 18px;
margin-right: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.extra-dots-box .extra-dot:hover{
cursor: pointer;
}
.extra-dots-box .extra-dot:hover,.extra-dots-box .extra-dot.active {
background: red;
}
jQuery
$(document).ready(function() {
var slickOpts = {
slidesToShow: 1,
slidesToScroll: 1,
//centerMode: true,
easing: 'swing', // see http://api.jquery.com/animate/
speed: 700,
dots: true,
customPaging: function(slick,index) {
return '<a>' + (index + 1) + '</a>';
}
};
// Init slick carousel
$('#carousel').slick(slickOpts);
});
jQuery(document).ready(function($) {
$('.slider-for').slick({
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
dots: true,
customPaging: function(slick,index) {
return '<a>' + (index + 1) + '</a>';
},
asNavFor: '.slider-nav'
});
//set active class to first slide
$('.slider-nav .slick-slide').eq(0).addClass('slick-active');
$('.slider-nav').slick({
slidesToShow: 6,
slidesToScroll: 1,
asNavFor: '.slider-for',
dots: false,
focusOnSelect: true,
responsive: [{
breakpoint: 992,
settings: {
vertical: false,
}
},
{
breakpoint: 768,
settings: {
vertical: false,
}
},
{
breakpoint: 580,
settings: {
vertical: false,
slidesToShow: 3,
}
},
{
breakpoint: 380,
settings: {
vertical: false,
slidesToShow: 2,
}
}
]
});
$('.slider-nav').on('mouseover', '.slick-slide', function (e) {
var $currTarget = $(e.currentTarget),
index = $currTarget.data('slick-index'),
slickObj = $('.slider-for').slick('getSlick');
slickObj.slickGoTo(index);
});
});
.slider-item {
border: 5px solid #333;
background: #ccc;
height: 200px;
font-size: 72px;
text-align: center;
line-height: 200px;
}
/* Slider arrows */
.slick-arrow {
z-index: 9;
}
.slick-prev {
left: 0;
}
.slick-next {
right: 0;
}
/* extra dots */
.extra-dots-box{
display: flex;
margin-top: 100px;
margin-bottom: 100px;
}
.extra-dots-box .extra-dot{
width: 350px;
height: 250px;
background: #111111;
color: #ffffff;
font-size: 18px;
margin-right: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.extra-dots-box .extra-dot:hover{
cursor: pointer;
}
.extra-dots-box .extra-dot:hover,.extra-dots-box .extra-dot.active {
background: red;
}
/*For dots*/
.slick-dots {
position: absolute;
bottom: -45px;
display: block;
width: 100%;
padding: 0;
list-style: none;
text-align: center;
}
.slick-dots li {
position: relative;
display: inline-block;
width: 20px;
height: 20px;
margin: 0 5px;
padding: 0;
cursor: pointer;
}
.slider-nav .slick-slide.slick-current.slick-active .extra-dot {
border: 1px solid #80D6CF;
border-radius: 2px;
background-color: red;
box-shadow: 0 0 2px 0 rgba(0,0,0,0.1), 0 2px 4px 0 rgba(0,0,0,0.1);
padding: 3px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<div id="carousel" class="slider slider-for">
<div class="slider-item">1</div>
<div class="slider-item">2</div>
<div class="slider-item">3</div>
</div>
<div class="extra-dots-box slider-nav thumb-image">
<div class="dot-1 extra-dot">
<span>1</span>
<h3>Custom Title</h3>
<p>lorem ipsum lorem ipsum</p>
</div>
<div class="dot-2 extra-dot">
<span>2</span>
<h3>Custom Title</h3>
<p>lorem ipsum lorem ipsum</p>
</div>
<div class="dot-3 extra-dot">
<span>3</span>
<h3>Custom Title</h3>
<p>lorem ipsum lorem ipsum</p>
</div>
</div>
I'm using Swiper to create some image sliders, and I'm trying to enclose the sliders within 2 flexbox containers such that my images are responsive.
I'd like to add some text on top of the images, aligned with the upper left corner of the image, and this is where everything goes wrong.
I believe I'm dealing with Flexbox "problem" very similar to Why don't flex items shrink past content size? in which case the parent DIV is keeping the width of the original image. The problem is the fixes in the post don't appear to work once I wrap the image in <div class="img-wrapper">. In fact I've spent quite a bit of time researching, and nothing quite seems to get it working the way I want.
This question is a fork of CSS object-fit: contain; is keeping original image width in layout
NOTE: Open the below code snippet in a new window to see the issue.
var swiper = new Swiper('.swiper-container', {
slidesPerView: 1,
spaceBetween: 50,
// init: false,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
img {
object-fit: contain;
min-width: 0;
height: 100%;
max-width: 100%;
}
.img-num {
float: left;
position: absolute;
padding-left: 10px;
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
color: white;
font: 1.5em Georgia, serif;
}
.img-wrapper {
border-style: solid;
border-width: thin;
height: 100%;
object-fit: contain;
min-width: 0;
}
html,
body {
margin: 0;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.page {
height: 100%;
display: flex;
}
.main-container {
flex: 1 1 0;
display: flex;
min-width: 0;
flex-direction: column;
}
.half-containers {
flex: 0 1 50%;
overflow: auto;
box-sizing: border-box;
border: 0.5px solid red;
display: flex;
}
.page-header {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.page-footer {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.css" rel="stylesheet" />
<div class="page">
<div class="main-container">
<div class="page-header">
This is a header
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">1</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">2</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">3</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">4</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="page-footer">
This is a footer
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.js"></script>
First, the use of object-fit is useless when applied to a div and not to the image1. Even the use of it within the image in this case is useless because the image is not getting distorted. object-fit only apply when the ratio is lost in order to bring it back again.
So you will have the same issue without:
var swiper = new Swiper('.swiper-container', {
slidesPerView: 1,
spaceBetween: 50,
// init: false,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
img {
height: 100%;
max-width: 100%;
}
.img-num {
float: left;
position: absolute;
padding-left: 10px;
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
color: white;
font: 1.5em Georgia, serif;
}
.img-wrapper {
border-style: solid;
border-width: thin;
height: 100%;
}
html,
body {
margin: 0;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.page {
height: 100%;
display: flex;
}
.main-container {
flex: 1 1 0;
display: flex;
min-width: 0;
flex-direction: column;
}
.half-containers {
flex: 0 1 50%;
overflow: auto;
box-sizing: border-box;
border: 0.5px solid red;
display: flex;
}
.page-header {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.page-footer {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.css" rel="stylesheet" />
<div class="page">
<div class="main-container">
<div class="page-header">
This is a header
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">1</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">2</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">3</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">4</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="page-footer">
This is a footer
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.js"></script>
Now the issue you are facing is that the image wrapper is first sized considerd the image width then the image is getting resized inside that wrapper. It's somehow complex but if you remove height:100% from the image you will have this:
var swiper = new Swiper('.swiper-container', {
slidesPerView: 1,
spaceBetween: 50,
// init: false,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
img {
/*height: 100%;*/
max-width: 100%;
}
.img-num {
float: left;
position: absolute;
padding-left: 10px;
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
color: white;
font: 1.5em Georgia, serif;
}
.img-wrapper {
border-style: solid;
border-width: thin;
height: 100%;
}
html,
body {
margin: 0;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.page {
height: 100%;
display: flex;
}
.main-container {
flex: 1 1 0;
display: flex;
min-width: 0;
flex-direction: column;
}
.half-containers {
flex: 0 1 50%;
overflow: auto;
box-sizing: border-box;
border: 0.5px solid red;
display: flex;
}
.page-header {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.page-footer {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.css" rel="stylesheet" />
<div class="page">
<div class="main-container">
<div class="page-header">
This is a header
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">1</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">2</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">3</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">4</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="page-footer">
This is a footer
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.js"></script>
This is actually what you want considering the width but the height is big thus the image is overflowing. By adding height:100% you will decrease the height and also the width because the image will try to keep its ratio. Of course, the wrapper will not get resized again because will have a cycle thus it will stuck at that size.
An easy fix is to simply make the image wrapper position: absolute;. its height is already defined as 100% and its width will shrink to fit the image width. No need to adjust top/left because it's already centred without the use of absolute thus it will be kept centred:
var swiper = new Swiper('.swiper-container', {
slidesPerView: 1,
spaceBetween: 50,
// init: false,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
img {
height: 100%;
max-width: 100%;
}
.img-num {
top:0;
left:0;
position: absolute;
padding-left: 10px;
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
color: white;
font: 1.5em Georgia, serif;
}
.img-wrapper {
border-style: solid;
border-width: thin;
height: 100%;
position: absolute;
}
html,
body {
margin: 0;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.page {
height: 100%;
display: flex;
}
.main-container {
flex: 1 1 0;
display: flex;
min-width: 0;
flex-direction: column;
}
.half-containers {
flex: 0 1 50%;
overflow: auto;
box-sizing: border-box;
border: 0.5px solid red;
display: flex;
}
.page-header {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.page-footer {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.css" rel="stylesheet" />
<div class="page">
<div class="main-container">
<div class="page-header">
This is a header
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">1</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">2</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">3</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">4</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="page-footer">
This is a footer
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.js"></script>
1The object-fit property specifies how the contents of a replaced element should be fitted to the box established by its used height and width.ref
A div is not a replaced element. Replaced elements are element like canvas, img, iframe, etc (https://html.spec.whatwg.org/multipage/rendering.html#replaced-elements)
UPDATE
The above seems to work only on Chrome so I would consider a small JS hack to rectify the width of the element on the other browsers:
var swiper = new Swiper('.swiper-container', {
slidesPerView: 1,
spaceBetween: 50,
// init: false,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
$('.img-wrapper').each(function() {
$(this).width($(this).find('img').width())
})
$( window ).resize(function() {
$('.img-wrapper').each(function() {
$(this).css('width','100%').width($(this).find('img').width())
})
});
img {
height: 100%;
max-width: 100%;
object-fit:cover;
}
.img-num {
top:0;
left:0;
position: absolute;
padding-left: 10px;
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
color: white;
font: 1.5em Georgia, serif;
}
.img-wrapper {
border-style: solid;
border-width: thin;
height: 100%;
position: absolute;
max-width:100%;
}
html,
body {
margin: 0;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.page {
height: 100%;
display: flex;
}
.main-container {
flex: 1 1 0;
display: flex;
min-width: 0;
flex-direction: column;
}
.half-containers {
flex: 0 1 50%;
overflow: auto;
box-sizing: border-box;
border: 0.5px solid red;
display: flex;
}
.page-header {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.page-footer {
flex: 0 0 auto;
background-color: #dcdcdc;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.css" rel="stylesheet" />
<div class="page">
<div class="main-container">
<div class="page-header">
This is a header
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">1</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">2</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="half-containers">
<!-- Swiper -->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">3</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
<div class="swiper-slide">
<div class="img-wrapper">
<div class="img-num">4</div>
<img src='https://i.imgur.com/mSPw98T.jpg' />
</div>
</div>
</div>
</div>
</div>
<div class="page-footer">
This is a footer
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.js"></script>