Monday, August 10, 2015

How to create a simple image slider using css

HTML Code:

<div id="image-slider">
   <figure>
       <img src="http://www.dan-dare.org/FreeFun/Images/CartoonsMoviesTV/MadagascarWallpaper21024.jpg" alt="">
       <img src="http://img2.goodfon.su/original/1024x768/8/94/dota-2-nature-s-prophet-riki.jpg" alt="">
       <img src="http://hdwallpapersbase.com/wp-content/uploads/2013/01/kung-fu-panda-legends-of-awesomeness-wallpaper.jpg" alt="">
        <img src="http://www.cartoonpics.net/data/media/31/ice_age_team.jpg" alt="">
        <img src="http://hdwallpapersbase.com/wp-content/uploads/2013/01/ice-age-4-continental-drift-wallpapers-.jpg" alt="">
   </figure>
</div>


CSS Code:

@keyframes slide-effect {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}

body { margin: 0; } 
#image-slider { overflow: hidden; }
#image-slider figure img { width: 20%; float: left; }
#image-slider figure { 
  position: relative;
  width: 500%;
  margin: 0;
  left: 0;
  text-align: left;
  font-size: 0;
  animation: 30s slide-effect infinite; 
}



Finally Code is Like this


<!DOCTYPE html>
<html>
<head>
<style>
@keyframes slide-effect {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}

body { margin: 0; } 
#image-slider { overflow: hidden; }
#image-slider figure img { width: 20%; float: left; }
#image-slider figure { 
  position: relative;
  width: 500%;
  margin: 0;
  left: 0;
  text-align: left;
  font-size: 0;
  animation: 30s slide-effect infinite; 
}
</style>
</head>
<body>
<div id="image-slider">
<figure>
<img src="http://demosthenes.info/assets/images/austin-fireworks.jpg" alt="">
<img src="http://demosthenes.info/assets/images/taj-mahal.jpg" alt="">
<img src="http://demosthenes.info/assets/images/ankor-wat.jpg" alt="">
<img src="http://demosthenes.info/assets/images/austin-fireworks.jpg" alt="">
</figure>
</div>
</body>
</html>
Continue Reading →

Popular Posts