1 Answer

0 votes
by (487 points)

Hello, friends. Today I am going to show you how to make a image slider using html and css code in home page or any other page you want. 

At first. enter the folder named 'DefaultPage' in main directory. 

Then opening the folder and you delete all the files and folder keeping 'index.html' file.( You must keep backup this folder in your laptop). After that, just edit the file index.html file using notepad and delete all code from index file. Then copy the code below and paste in that index file and save.

Image slider code for index.html file

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

* {box-sizing: border-box;}

body {

  margin: 0;

  font-family: arial black, Verdana, sans-serif;

  display: relative;

  flex-direction: column;

  align-items: center;

  height: 65vh;

  justify-content: center;

  overflow: hidden;}

.mySlides {display: none;}

img {vertical-align: middle;}

/* Slideshow container */

.slideshow-container {

  max-width: 1000px;

  position: relative;

  margin: auto;

}

/* Caption text */

.text {

  color: #f2f2f2;

  font-size: 25px;

  padding: 8px 12px;

  position: absolute;

  bottom: 8px;

  width: 100%;

  text-align: center;

}

/* Number text (1/3 etc) */

.numbertext {

  color: #f2f2f2;

  font-size: 12px;

  padding: 8px 12px;

  position: absolute;

  top: 5px;

}

/* The dots/bullets/indicators */

.dot {

  height: 15px;

  width: 15px;

  margin: 0 2px;

  background-color: #bbb;

  border-radius: 50%;

  display: inline-block;

  transition: background-color 0.6s ease;

}

.active {

  background-color: #717171;

}

/* Fading animation */

.fade {

  animation-name: fade;

  animation-duration: 1.5s;

}

@keyframes fade {

  from {opacity: .4} 

  to {opacity: 1}

}

/* On smaller screens, decrease text size */

@media only screen and (max-width: 300px) {

  .text {font-size: 11px}

}

</style>

</head>

<body>

<div class="slideshow-container">

<div class="mySlides fade">

  <div class="numbertext">1 / 7</div>

  <img src="image1.jpg" style="width:100%">

  <div class="text">বিদ্যালয় ভবন </div>

</div>

<div class="mySlides fade">

  <div class="numbertext">2 / 7</div>

  <img src="image2.jpg" style="width:100%">

  <div class="text"> শহীদ মিনার</div>

</div>

<div class="mySlides fade">

  <div class="numbertext">3 / 7</div>

  <img src="image3.jpg" style="width:100%">

  <div class="text">ওয়াশরুম</div>

</div>

<div class="mySlides fade">

  <div class="numbertext">4 / 7</div>

  <img src="image4.jpg" style="width:100%">

  <div class="text">দৈনিক সমাবেশ</div>

</div>

<div class="mySlides fade">

  <div class="numbertext">5 / 7</div>

  <img src="image5.jpg" style="width:100%">

  <div class="text">দৈনিক সমাবেশ</div>

</div>

<div class="mySlides fade">

  <div class="numbertext">6 / 7</div>

  <img src="image6.jpg" style="width:100%">

  <div class="text"></div>

</div>

<div class="mySlides fade">

  <div class="numbertext">7 / 7</div>

  <img src="image7.jpg" style="width:100%">

  <div class="text"></div>

</div>

</div>

<br>

<div style="text-align:center">

  <span class="dot"></span> 

  <span class="dot"></span> 

  <span class="dot"></span>

  <span class="dot"></span>

  <span class="dot"></span> 

  <span class="dot"></span> 

  <span class="dot"></span> 

</div>

<script>

let slideIndex = 0;

showSlides();

function showSlides() {

  let i;

  let slides = document.getElementsByClassName("mySlides");

  let 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); // Change image every 2 seconds

}

</script>

</body>

</html> 

Change the text for image caption at your own language and save.

After that copy and paste some images in the 'DefaultPage' folder. Remember, the images name will be image1, image2, image3, image4, image5. Now enjoy....

312 questions

91 answers

6 comments

5,034 users

5 Online Users
0 Member 5 Guest
Today Visits : 7532
Yesterday Visits : 2524
Total Visits : 6983322
...