Slick carousel - force slides to have the same height












6















Im having trouble with the Slick carousel JS plugin with multiple slidesToShow which have different heights.



I need the Slides to have the same height, but with CSS flex-box it doesnt work as the slides have conflicting CSS definitions.



Also didn't find anything usefull in the forums and on the web.



If i get something working, i will post the solution here.
Of course any suggestions are welcome.



HTML



<div class="slider">
<div class="slide">
<p>Lorem ipsum.</p>
</div>
<div class="slide">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
</div>
<div class="slide">
<p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<div class="slide">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
</div>
</div>


JS



$('.slider')
.slick({
autoplay: false,
dots: false,
infinite: false,
arrows: false,
slidesToShow: 2,
slidesToScroll: 2,
rows: 0
});


CSS



.slide {
height: 100%;
background-color: #ccc;
padding: 10px;
}









share|improve this question



























    6















    Im having trouble with the Slick carousel JS plugin with multiple slidesToShow which have different heights.



    I need the Slides to have the same height, but with CSS flex-box it doesnt work as the slides have conflicting CSS definitions.



    Also didn't find anything usefull in the forums and on the web.



    If i get something working, i will post the solution here.
    Of course any suggestions are welcome.



    HTML



    <div class="slider">
    <div class="slide">
    <p>Lorem ipsum.</p>
    </div>
    <div class="slide">
    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
    </div>
    <div class="slide">
    <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
    </div>
    <div class="slide">
    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
    </div>
    </div>


    JS



    $('.slider')
    .slick({
    autoplay: false,
    dots: false,
    infinite: false,
    arrows: false,
    slidesToShow: 2,
    slidesToScroll: 2,
    rows: 0
    });


    CSS



    .slide {
    height: 100%;
    background-color: #ccc;
    padding: 10px;
    }









    share|improve this question

























      6












      6








      6


      1






      Im having trouble with the Slick carousel JS plugin with multiple slidesToShow which have different heights.



      I need the Slides to have the same height, but with CSS flex-box it doesnt work as the slides have conflicting CSS definitions.



      Also didn't find anything usefull in the forums and on the web.



      If i get something working, i will post the solution here.
      Of course any suggestions are welcome.



      HTML



      <div class="slider">
      <div class="slide">
      <p>Lorem ipsum.</p>
      </div>
      <div class="slide">
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
      </div>
      <div class="slide">
      <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
      </div>
      <div class="slide">
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
      </div>
      </div>


      JS



      $('.slider')
      .slick({
      autoplay: false,
      dots: false,
      infinite: false,
      arrows: false,
      slidesToShow: 2,
      slidesToScroll: 2,
      rows: 0
      });


      CSS



      .slide {
      height: 100%;
      background-color: #ccc;
      padding: 10px;
      }









      share|improve this question














      Im having trouble with the Slick carousel JS plugin with multiple slidesToShow which have different heights.



      I need the Slides to have the same height, but with CSS flex-box it doesnt work as the slides have conflicting CSS definitions.



      Also didn't find anything usefull in the forums and on the web.



      If i get something working, i will post the solution here.
      Of course any suggestions are welcome.



      HTML



      <div class="slider">
      <div class="slide">
      <p>Lorem ipsum.</p>
      </div>
      <div class="slide">
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
      </div>
      <div class="slide">
      <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
      </div>
      <div class="slide">
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
      </div>
      </div>


      JS



      $('.slider')
      .slick({
      autoplay: false,
      dots: false,
      infinite: false,
      arrows: false,
      slidesToShow: 2,
      slidesToScroll: 2,
      rows: 0
      });


      CSS



      .slide {
      height: 100%;
      background-color: #ccc;
      padding: 10px;
      }






      javascript jquery css slick.js web-frontend






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 28 '18 at 11:48









      JJaunJJaun

      20439




      20439
























          5 Answers
          5






          active

          oldest

          votes


















          12














          Ok guys i found an easy solution. Just add a setPosition callback function (fires after position/size changes) which sets the height of the slides to the height of the slider (slideTrack):



          JS



          $('.slider').slick({
          autoplay: false,
          dots: false,
          infinite: false,
          arrows: false,
          slidesToShow: 2,
          slidesToScroll: 2,
          rows: 0
          })
          .on('setPosition', function (event, slick) {
          slick.$slides.css('height', slick.$slideTrack.height() + 'px');
          });


          Dont forget that your slides need to have full height:



          CSS



          .slide {
          height: 100%;
          }


          Here is a little jsFiddle to demonstrate:
          https://jsfiddle.net/JJaun/o29a4q45/






          share|improve this answer



















          • 1





            I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

            – user1406440
            Jul 30 '18 at 21:58











          • You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

            – jdbosley
            Oct 4 '18 at 18:13











          • You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

            – minlare
            Dec 6 '18 at 10:40



















          4














          Add a couple of CSS styles and it will be ready:



          .slick-track
          {
          display: flex !important;
          }

          .slick-slide
          {
          height: inherit !important;
          }


          Enjoy! :-)






          share|improve this answer



















          • 1





            Great! This code is working like a charm with the new version (1.9.0).

            – Reza Mamun
            Nov 8 '18 at 15:01



















          2














          I've another css-only solution. you can override floated elements with table/table-cell.






          $(function() {
          $('.slider')
          .slick({
          autoplay: false,
          dots: false,
          infinite: false,
          arrows: false,
          slidesToShow: 2,
          slidesToScroll: 2,
          rows: 0
          });
          })

          .slide {
          background-color: #ccc;
          padding: 10px;
          display: table-cell !important;
          float: none !important;
          }

          .slick-track {
          display: table !important;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


          <div class="slider">
          <div class="slide">
          <p>Lorem ipsum.</p>
          </div>
          <div class="slide">
          <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
          </div>
          <div class="slide">
          <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
          </div>
          <div class="slide">
          <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
          </div>
          </div>








          share|improve this answer
























          • yes thanks a lot man! this works just fine.

            – JJaun
            Feb 28 '18 at 13:16











          • in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

            – JJaun
            Feb 28 '18 at 13:20











          • @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

            – ocanal
            Feb 28 '18 at 14:00













          • setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

            – ocanal
            Feb 28 '18 at 14:10






          • 1





            @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

            – ocanal
            Jul 31 '18 at 8:09



















          0














          I've wrote a quick JS hack to make a gallery with different images heights to look a little neater.



          It does the following:




          1. Get slider instance

          2. Find out it's height - images height will be set to that

          3. Get the src attr for each image and hide it


          4. Set src attr to image's parent as a background image together with some CSS.



            function equalizeImagesHeight(slider) {
            const slides = slider.find('.slick-slide');
            const imgHeight = $(slider)[0].clientHeight;
            slides.each(function(slide){
            const src = $(this).find('img').hide().attr('src');
            $(this).css({
            backgroundImage:'url('+src+')',
            minHeight: imgHeight,
            backgroundSize: "cover",
            backgroundPosition: "center"
            });
            });
            };


            equalizeImagesHeight($('.my-slider'));








          share|improve this answer































            0














            The js solution from @JJaun is not perfect, because you see the height jumping if you use an background image for the slides. This worked for me:





            .slick-track {
            display: flex !important;
            }

            .slick-slide {
            height: auto;
            }







            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49028877%2fslick-carousel-force-slides-to-have-the-same-height%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              12














              Ok guys i found an easy solution. Just add a setPosition callback function (fires after position/size changes) which sets the height of the slides to the height of the slider (slideTrack):



              JS



              $('.slider').slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              })
              .on('setPosition', function (event, slick) {
              slick.$slides.css('height', slick.$slideTrack.height() + 'px');
              });


              Dont forget that your slides need to have full height:



              CSS



              .slide {
              height: 100%;
              }


              Here is a little jsFiddle to demonstrate:
              https://jsfiddle.net/JJaun/o29a4q45/






              share|improve this answer



















              • 1





                I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

                – user1406440
                Jul 30 '18 at 21:58











              • You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

                – jdbosley
                Oct 4 '18 at 18:13











              • You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

                – minlare
                Dec 6 '18 at 10:40
















              12














              Ok guys i found an easy solution. Just add a setPosition callback function (fires after position/size changes) which sets the height of the slides to the height of the slider (slideTrack):



              JS



              $('.slider').slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              })
              .on('setPosition', function (event, slick) {
              slick.$slides.css('height', slick.$slideTrack.height() + 'px');
              });


              Dont forget that your slides need to have full height:



              CSS



              .slide {
              height: 100%;
              }


              Here is a little jsFiddle to demonstrate:
              https://jsfiddle.net/JJaun/o29a4q45/






              share|improve this answer



















              • 1





                I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

                – user1406440
                Jul 30 '18 at 21:58











              • You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

                – jdbosley
                Oct 4 '18 at 18:13











              • You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

                – minlare
                Dec 6 '18 at 10:40














              12












              12








              12







              Ok guys i found an easy solution. Just add a setPosition callback function (fires after position/size changes) which sets the height of the slides to the height of the slider (slideTrack):



              JS



              $('.slider').slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              })
              .on('setPosition', function (event, slick) {
              slick.$slides.css('height', slick.$slideTrack.height() + 'px');
              });


              Dont forget that your slides need to have full height:



              CSS



              .slide {
              height: 100%;
              }


              Here is a little jsFiddle to demonstrate:
              https://jsfiddle.net/JJaun/o29a4q45/






              share|improve this answer













              Ok guys i found an easy solution. Just add a setPosition callback function (fires after position/size changes) which sets the height of the slides to the height of the slider (slideTrack):



              JS



              $('.slider').slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              })
              .on('setPosition', function (event, slick) {
              slick.$slides.css('height', slick.$slideTrack.height() + 'px');
              });


              Dont forget that your slides need to have full height:



              CSS



              .slide {
              height: 100%;
              }


              Here is a little jsFiddle to demonstrate:
              https://jsfiddle.net/JJaun/o29a4q45/







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 28 '18 at 11:55









              JJaunJJaun

              20439




              20439








              • 1





                I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

                – user1406440
                Jul 30 '18 at 21:58











              • You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

                – jdbosley
                Oct 4 '18 at 18:13











              • You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

                – minlare
                Dec 6 '18 at 10:40














              • 1





                I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

                – user1406440
                Jul 30 '18 at 21:58











              • You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

                – jdbosley
                Oct 4 '18 at 18:13











              • You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

                – minlare
                Dec 6 '18 at 10:40








              1




              1





              I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

              – user1406440
              Jul 30 '18 at 21:58





              I'm having a similar issue with a carousel. I tried to apply the setPosition fix to my script but it just breaks it. Can you see where I'm going wrong? codepen.io/moy/pen/KBZbZL

              – user1406440
              Jul 30 '18 at 21:58













              You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

              – jdbosley
              Oct 4 '18 at 18:13





              You should update this answer to first set the $slides height to "auto" otherwise on resize your height measurements will be inaccurate since your $slideTrack height will be off because it's children $slides have a fixed pixel height.

              – jdbosley
              Oct 4 '18 at 18:13













              You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

              – minlare
              Dec 6 '18 at 10:40





              You should update the answer to use slick.$slideTrack.find('.slick-slide') as cloned elements do not have the same height whilst transitioning.

              – minlare
              Dec 6 '18 at 10:40













              4














              Add a couple of CSS styles and it will be ready:



              .slick-track
              {
              display: flex !important;
              }

              .slick-slide
              {
              height: inherit !important;
              }


              Enjoy! :-)






              share|improve this answer



















              • 1





                Great! This code is working like a charm with the new version (1.9.0).

                – Reza Mamun
                Nov 8 '18 at 15:01
















              4














              Add a couple of CSS styles and it will be ready:



              .slick-track
              {
              display: flex !important;
              }

              .slick-slide
              {
              height: inherit !important;
              }


              Enjoy! :-)






              share|improve this answer



















              • 1





                Great! This code is working like a charm with the new version (1.9.0).

                – Reza Mamun
                Nov 8 '18 at 15:01














              4












              4








              4







              Add a couple of CSS styles and it will be ready:



              .slick-track
              {
              display: flex !important;
              }

              .slick-slide
              {
              height: inherit !important;
              }


              Enjoy! :-)






              share|improve this answer













              Add a couple of CSS styles and it will be ready:



              .slick-track
              {
              display: flex !important;
              }

              .slick-slide
              {
              height: inherit !important;
              }


              Enjoy! :-)







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 3 '18 at 13:54









              PhoenixPhoenix

              1861313




              1861313








              • 1





                Great! This code is working like a charm with the new version (1.9.0).

                – Reza Mamun
                Nov 8 '18 at 15:01














              • 1





                Great! This code is working like a charm with the new version (1.9.0).

                – Reza Mamun
                Nov 8 '18 at 15:01








              1




              1





              Great! This code is working like a charm with the new version (1.9.0).

              – Reza Mamun
              Nov 8 '18 at 15:01





              Great! This code is working like a charm with the new version (1.9.0).

              – Reza Mamun
              Nov 8 '18 at 15:01











              2














              I've another css-only solution. you can override floated elements with table/table-cell.






              $(function() {
              $('.slider')
              .slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              });
              })

              .slide {
              background-color: #ccc;
              padding: 10px;
              display: table-cell !important;
              float: none !important;
              }

              .slick-track {
              display: table !important;
              }

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


              <div class="slider">
              <div class="slide">
              <p>Lorem ipsum.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
              </div>
              <div class="slide">
              <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
              </div>
              </div>








              share|improve this answer
























              • yes thanks a lot man! this works just fine.

                – JJaun
                Feb 28 '18 at 13:16











              • in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

                – JJaun
                Feb 28 '18 at 13:20











              • @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

                – ocanal
                Feb 28 '18 at 14:00













              • setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

                – ocanal
                Feb 28 '18 at 14:10






              • 1





                @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

                – ocanal
                Jul 31 '18 at 8:09
















              2














              I've another css-only solution. you can override floated elements with table/table-cell.






              $(function() {
              $('.slider')
              .slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              });
              })

              .slide {
              background-color: #ccc;
              padding: 10px;
              display: table-cell !important;
              float: none !important;
              }

              .slick-track {
              display: table !important;
              }

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


              <div class="slider">
              <div class="slide">
              <p>Lorem ipsum.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
              </div>
              <div class="slide">
              <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
              </div>
              </div>








              share|improve this answer
























              • yes thanks a lot man! this works just fine.

                – JJaun
                Feb 28 '18 at 13:16











              • in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

                – JJaun
                Feb 28 '18 at 13:20











              • @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

                – ocanal
                Feb 28 '18 at 14:00













              • setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

                – ocanal
                Feb 28 '18 at 14:10






              • 1





                @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

                – ocanal
                Jul 31 '18 at 8:09














              2












              2








              2







              I've another css-only solution. you can override floated elements with table/table-cell.






              $(function() {
              $('.slider')
              .slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              });
              })

              .slide {
              background-color: #ccc;
              padding: 10px;
              display: table-cell !important;
              float: none !important;
              }

              .slick-track {
              display: table !important;
              }

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


              <div class="slider">
              <div class="slide">
              <p>Lorem ipsum.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
              </div>
              <div class="slide">
              <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
              </div>
              </div>








              share|improve this answer













              I've another css-only solution. you can override floated elements with table/table-cell.






              $(function() {
              $('.slider')
              .slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              });
              })

              .slide {
              background-color: #ccc;
              padding: 10px;
              display: table-cell !important;
              float: none !important;
              }

              .slick-track {
              display: table !important;
              }

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


              <div class="slider">
              <div class="slide">
              <p>Lorem ipsum.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
              </div>
              <div class="slide">
              <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
              </div>
              </div>








              $(function() {
              $('.slider')
              .slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              });
              })

              .slide {
              background-color: #ccc;
              padding: 10px;
              display: table-cell !important;
              float: none !important;
              }

              .slick-track {
              display: table !important;
              }

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


              <div class="slider">
              <div class="slide">
              <p>Lorem ipsum.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
              </div>
              <div class="slide">
              <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
              </div>
              </div>





              $(function() {
              $('.slider')
              .slick({
              autoplay: false,
              dots: false,
              infinite: false,
              arrows: false,
              slidesToShow: 2,
              slidesToScroll: 2,
              rows: 0
              });
              })

              .slide {
              background-color: #ccc;
              padding: 10px;
              display: table-cell !important;
              float: none !important;
              }

              .slick-track {
              display: table !important;
              }

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>


              <div class="slider">
              <div class="slide">
              <p>Lorem ipsum.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua</p>
              </div>
              <div class="slide">
              <p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
              </div>
              <div class="slide">
              <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
              </div>
              </div>






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 28 '18 at 12:07









              ocanalocanal

              9,2061556109




              9,2061556109













              • yes thanks a lot man! this works just fine.

                – JJaun
                Feb 28 '18 at 13:16











              • in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

                – JJaun
                Feb 28 '18 at 13:20











              • @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

                – ocanal
                Feb 28 '18 at 14:00













              • setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

                – ocanal
                Feb 28 '18 at 14:10






              • 1





                @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

                – ocanal
                Jul 31 '18 at 8:09



















              • yes thanks a lot man! this works just fine.

                – JJaun
                Feb 28 '18 at 13:16











              • in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

                – JJaun
                Feb 28 '18 at 13:20











              • @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

                – ocanal
                Feb 28 '18 at 14:00













              • setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

                – ocanal
                Feb 28 '18 at 14:10






              • 1





                @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

                – ocanal
                Jul 31 '18 at 8:09

















              yes thanks a lot man! this works just fine.

              – JJaun
              Feb 28 '18 at 13:16





              yes thanks a lot man! this works just fine.

              – JJaun
              Feb 28 '18 at 13:16













              in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

              – JJaun
              Feb 28 '18 at 13:20





              in my actual usecase i have to build this in a finished bootstrap layout which i can not really change...here i have bootstrap columns with cards inside and those cards are not the same hight as the actual slides...something linke this jsfiddle.net/JJaun/o29a4q45/22 got an idea how to fix it?

              – JJaun
              Feb 28 '18 at 13:20













              @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

              – ocanal
              Feb 28 '18 at 14:00







              @JJaun, hımm nested elements, it's getting complicated with css. Than you should do it with your js way (calculating height), here is the updated one, jsfiddle.net/o29a4q45/43

              – ocanal
              Feb 28 '18 at 14:00















              setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

              – ocanal
              Feb 28 '18 at 14:10





              setting height of content triggers setPosition again. i've added a fix. check it again jsfiddle.net/o29a4q45/49

              – ocanal
              Feb 28 '18 at 14:10




              1




              1





              @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

              – ocanal
              Jul 31 '18 at 8:09





              @user1406440, i've changed resort to tile, and some minor fixes, updated one is here, codepen.io/anon/pen/QBQjWp

              – ocanal
              Jul 31 '18 at 8:09











              0














              I've wrote a quick JS hack to make a gallery with different images heights to look a little neater.



              It does the following:




              1. Get slider instance

              2. Find out it's height - images height will be set to that

              3. Get the src attr for each image and hide it


              4. Set src attr to image's parent as a background image together with some CSS.



                function equalizeImagesHeight(slider) {
                const slides = slider.find('.slick-slide');
                const imgHeight = $(slider)[0].clientHeight;
                slides.each(function(slide){
                const src = $(this).find('img').hide().attr('src');
                $(this).css({
                backgroundImage:'url('+src+')',
                minHeight: imgHeight,
                backgroundSize: "cover",
                backgroundPosition: "center"
                });
                });
                };


                equalizeImagesHeight($('.my-slider'));








              share|improve this answer




























                0














                I've wrote a quick JS hack to make a gallery with different images heights to look a little neater.



                It does the following:




                1. Get slider instance

                2. Find out it's height - images height will be set to that

                3. Get the src attr for each image and hide it


                4. Set src attr to image's parent as a background image together with some CSS.



                  function equalizeImagesHeight(slider) {
                  const slides = slider.find('.slick-slide');
                  const imgHeight = $(slider)[0].clientHeight;
                  slides.each(function(slide){
                  const src = $(this).find('img').hide().attr('src');
                  $(this).css({
                  backgroundImage:'url('+src+')',
                  minHeight: imgHeight,
                  backgroundSize: "cover",
                  backgroundPosition: "center"
                  });
                  });
                  };


                  equalizeImagesHeight($('.my-slider'));








                share|improve this answer


























                  0












                  0








                  0







                  I've wrote a quick JS hack to make a gallery with different images heights to look a little neater.



                  It does the following:




                  1. Get slider instance

                  2. Find out it's height - images height will be set to that

                  3. Get the src attr for each image and hide it


                  4. Set src attr to image's parent as a background image together with some CSS.



                    function equalizeImagesHeight(slider) {
                    const slides = slider.find('.slick-slide');
                    const imgHeight = $(slider)[0].clientHeight;
                    slides.each(function(slide){
                    const src = $(this).find('img').hide().attr('src');
                    $(this).css({
                    backgroundImage:'url('+src+')',
                    minHeight: imgHeight,
                    backgroundSize: "cover",
                    backgroundPosition: "center"
                    });
                    });
                    };


                    equalizeImagesHeight($('.my-slider'));








                  share|improve this answer













                  I've wrote a quick JS hack to make a gallery with different images heights to look a little neater.



                  It does the following:




                  1. Get slider instance

                  2. Find out it's height - images height will be set to that

                  3. Get the src attr for each image and hide it


                  4. Set src attr to image's parent as a background image together with some CSS.



                    function equalizeImagesHeight(slider) {
                    const slides = slider.find('.slick-slide');
                    const imgHeight = $(slider)[0].clientHeight;
                    slides.each(function(slide){
                    const src = $(this).find('img').hide().attr('src');
                    $(this).css({
                    backgroundImage:'url('+src+')',
                    minHeight: imgHeight,
                    backgroundSize: "cover",
                    backgroundPosition: "center"
                    });
                    });
                    };


                    equalizeImagesHeight($('.my-slider'));









                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 5 '18 at 15:06









                  Damian DrozdowiczDamian Drozdowicz

                  1




                  1























                      0














                      The js solution from @JJaun is not perfect, because you see the height jumping if you use an background image for the slides. This worked for me:





                      .slick-track {
                      display: flex !important;
                      }

                      .slick-slide {
                      height: auto;
                      }







                      share|improve this answer




























                        0














                        The js solution from @JJaun is not perfect, because you see the height jumping if you use an background image for the slides. This worked for me:





                        .slick-track {
                        display: flex !important;
                        }

                        .slick-slide {
                        height: auto;
                        }







                        share|improve this answer


























                          0












                          0








                          0







                          The js solution from @JJaun is not perfect, because you see the height jumping if you use an background image for the slides. This worked for me:





                          .slick-track {
                          display: flex !important;
                          }

                          .slick-slide {
                          height: auto;
                          }







                          share|improve this answer













                          The js solution from @JJaun is not perfect, because you see the height jumping if you use an background image for the slides. This worked for me:





                          .slick-track {
                          display: flex !important;
                          }

                          .slick-slide {
                          height: auto;
                          }








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 13:21









                          Artem BrunerArtem Bruner

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49028877%2fslick-carousel-force-slides-to-have-the-same-height%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Xamarin.iOS Cant Deploy on Iphone

                              Glorious Revolution

                              Dulmage-Mendelsohn matrix decomposition in Python