Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I show an image and half the next one in a scrolling row?

I am trying to create a div with two images inside that you can horizontally scroll through. Each image should be the full size of the div, and upon scrolling to the right you reveal the next image. My issue is that only the right half of the first image is displayed in the div, with the left half of the second image visible next to it. When you scroll you can see the right half of the second image. How can I make it so the entirety of the first image is visible?

.carousel {
  height: 74%;
  width: 85%;
  margin-left: 7.5%;
  margin-top: 0.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: scroll;
  overflow-y: hidden;
}

.carousel img {
  width: 85vw;
  height: 74vh;
  min-width: 100%;
}
<div class="carousel">
  <img src="https://via.placeholder.com/600x400">
  <img src="https://via.placeholder.com/600x400/dddddd">
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The problem is with justify-content: center. Remove that part of the code and it should work. Your code should look like:

.carousel {
  height: 74%;
  width: 85%;
  margin-left: 7.5%;
  margin-top: 0.5%;
  display: flex;
  align-items: center;
  overflow: scroll;
  overflow-y: hidden;
}

.carousel img {
  width: 85vw;
  height: 74vh;
  min-width: 100%;
}
<div class="carousel">
  <img src="https://via.placeholder.com/600x400">
  <img src="https://via.placeholder.com/600x400/dddddd">
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading