Hello friends how are you , Today in this post "How to create Image Slider using HTML and CSS" i am going to teach you how you can create an image slider using HTML and CSS with few lines of JavaScript code. If you want to create a website then you can use this slider into your project to make your website very attractive. If you wan to create something interesting using simple HTML and CSS then this post is for you.
If you want to understand this through video then watch this video i have explained it step by step live
Now i am going to explain step by step.
Step 1:Create a Folder: Just create a folder with any name and in any drive in your system, In my case my folder name is ImageSlider.
Step 2:Create an HTML file: Now open notepad and type the below code or you can copy this code for your personal use
<html> <head> <title>krazyprogrammers</title> <style> body{ background-color: black; font-family: Arial, Helvetica, sans-serif; } .mySlides { display: none; } img { vertical-align: middle; } .container { position: absolute; margin: auto; top: 50%; left: 50%; transform: translate(-50%,-50%); border: 5px groove lightgray; box-shadow: 1px 1px 20px cyan; } .text { color:white; font-size: 16px; padding: 20px 0px; position: absolute; bottom: 8px; width: 100%; text-align: center; } .numberText { color: white; font-size: 13px; padding: 8px 12px; position: absolute; top: 0; } .dot { height: 15px; width: 15px; margin:0 2px; background-color: cyan; border-radius: 125px; display: inline-block; transition: background-color 0.6s ease; } .active { background-color: orangered; } .fade { -webkit-animation-name: fade; -webkit-animation-duration: 1.5s; animation-name: fade; animation-duration: 1.5s; } @-webkit-keyframes fade{ from { opacity: 0.4; } to { opacity: 1; } } @keyframes fade{ from { opacity: 0.4; } to { opacity: 1; } } </style> </head> <body> <div class="container"> <div class="mySlides fade"> <div class="numberText">1/4</div> <img src="image/banner1.jpg" style="width: 1100px;height: 350px;"> <div class="text">Caption 1</div> </div> <div class="mySlides fade"> <div class="numberText">2/4</div> <img src="image/banner2.jpg" style="width: 1100px;height: 350px;"> <div class="text">Caption 2</div> </div> <div class="mySlides fade"> <div class="numberText">3/4</div> <img src="image/banner3.jpg" style="width: 1100px;height: 350px;"> <div class="text">Caption 3</div> </div> <div class="mySlides fade"> <div class="numberText">4/4</div> <img src="image/banner4.jpg" style="width: 1100px;height: 350px;"> <div class="text">Caption 4</div> </div> <div style="text-align: center;"> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> <span class="dot"></span> </div> </div> <script> var slideIndex=0; showSlides(); function showSlides() { var i; var slides=document.getElementsByClassName("mySlides"); var dots=document.getElementsByClassName("dot") for(i=0;i<slides.length;i++) { slides[i].style.display="none"; } slideIndex++; if(slideIndex>slides.length) { slideIndex=1 } for(i=0;i<dots.length;i++) { dots[i].className=dots[i].className.replace(" active",""); } slides[slideIndex-1].style.display="block"; dots[slideIndex-1].className+=" active"; setTimeout(showSlides,2000); } </script> </body> </html>
0 Comments