I suggest you use the background for li instead of img as follows:
<body> <div id="slides"> <ul> <li id="img1"></li> <li id="img2"></li> <li id="img3"></li> <li id="img4"></li> </ul> </div>
then you just set the global background property (CSS):
#slides li { width: 100%; height: 100%; background-size: cover; background-repeat: no-repeat; }
and set single background images individually (CSS)
#img1 { background: url(the_url_1.jpg); } #img2 { background: url(the_url_2.jpg); }
the background-size property does the magic:
if you set it as cover , you scale the background image as much as possible so that the background area is completely covered by the background image. Some parts of the background image may not be displayed in the background positioning area;
if you set it as contain , you scale the image to the largest size so that its width and height can fit into the content area;
source share