1

I have set up a carousel with a display flex:1 the idea being to make it take up as much height as available to it which works as intended(can be tested by setting a fixed height for the div(.image-iframeContainer) contained in it). but whenever I try and set this div to be 100% of the carousel height instead of the content scaling to fit the size of the carousel, the carousel will instead scale to the 100% of the size of the content(test this by stretching the aspect ratio). how do I fix/stop this happening?

reactjs

<div className="Cards">
              <Carousel
                showThumbs={false}
                infiniteLoop={true}
                swipeable={false}
                dynamicHeight={false}
              >
                <div>
                  <div className="image-iframeContainer">
                    <img src={IMG} />
                  </div>
                </div>
                <div>
                  <div className="image-iframeContainer">
                    <img src={IMG} />
                  </div>
                </div>
                <div>
                  <div className="image-iframeContainer">
                    <img src={IMG} />
                  </div>
                </div>
              </Carousel>
              <h1>{Projects.workName}</h1>
              {Projects.workTech.map((Tech, index) => {
                return <p>Technology used: {Tech}</p>;
              })}
              <p>{Projects.workDescription}</p>
            </div>

Sass

.Cards {
    position: absolute;
    width: 50%;
    height: 80%;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.2);
    margin-left: auto;
    margin-right: auto;
    margin-top: 10%;
    left: 0;
    right: 0;
    border-radius: 7px;
    overflow: hidden;
    background: #7510f7;
    display: flex;
    flex-direction: column;


      .image-iframeContainer {
       display: flex;
    width: 100%;
     //setting a fixed height for this div allows for flex scaling of the carousel
    height: 400px;
    //height: 100%;
    background: greenyellow;
    overflow: hidden;


        img {
            width: auto;
            height: auto;
            max-width: 100%;
            max-height: 100%;
            object-fit: cover;
            background-repeat: no-repeat;
            margin: auto;
        }

        iframe {
            position: absolute;
            margin: 0;
            top: 0;
            left: 0;
            width: 100%;
            height: 100px;
            border: 0;
        }
    }
          .carousel-root{
            flex:1;
          }

      .carousel {
        z-index: 0;
    }

    .carousel, .slider-wrapper, .slider {
      height: 100%;
    }

    .slide{
      display: flex;
      justify-content: center;
    }

    .carousel.carousel-slider {
        .control-arrow {
            padding: 15%;
            opacity: 0%;
        }
    }
  }

sandbox link https://codesandbox.io/s/sleepy-sunset-jqjst?file=/src/styles.scss:478-500

To avoid confusion these are swipe cards layered on top of each other hence the absolute positioning, in my actual project images are injected dynamically I do not want to crop or stretch images this is why I've picked this implementation with borders the containing div will give back colour to the bezels around the picture.

lukeet
  • 461
  • 1
  • 4
  • 22

0 Answers0