1

I have a series of images in a slide show, which have all be uploaded at different image dimensions, I want to essentially make all the images follow a rule whereby they stretch, proportionally to the max width so that if you resize the browser window, they will still keep their fluid resizing response also.

Here is the website template and the images in question.

Would love to be able to do it in CSS if possible.

I'm having trouble stretching small images to fit into a larger container, rather than trying to contain large images in a small container. Usually the smaller image stops resizing once it's hit its actual pixel dims and I want them to continue to stretch proportionally, even if this pixelates them.

Andrew M
  • 11
  • 3

1 Answers1

2

The key to solving this is using background images and their CSS properties. Rather than inserting the images as <img> tags you should create containers with a background image set

<div class="slide" style="background-image: url(image1.jpg)"></div>

Give those containers some styling so they fill out your slideshow area.

position: absolute; top: 0; left: 0; display: block; width: 100%; height: 100%;

Then you can use background-size: contain; to make the image sit within the containers using pure CSS. It'll never extend outside of the area, but will fill it as much as possible. Also use background-position: center; and turn off image repeat using background-repeat: no-repeat; - then you'll have a single image centred and as large as it can be.

Full CSS is as follows:

position: absolute; top: 0; left: 0; display: block; width: 100%; height: 100%; background-size: contain; background-position: center; background-repeat: no-repeat;

You'll be able to use CSS transitions to control how the slideshow moves between slides.

Henry Gibson
  • 2,038
  • 2
  • 15
  • 12