Creating a Testimonial Slider Using HTML, CSS, and JavaScript #shorts

Posted by

body {
font-family: Arial, sans-serif;
}

.testimonial-container {
max-width: 600px;
margin: 0 auto;
}

.testimonial {
display: none;
}

.testimonial.active {
display: block;
}

.buttons {
text-align: center;
}

.button {
border: none;
background-color: #007bff;
color: white;
padding: 10px 20px;
margin: 10px;
cursor: pointer;
}

.button.active {
background-color: #0056b3;
}

John Doe

“I absolutely love this product! It has made my life so much easier.”

Jane Smith

“I was skeptical at first, but after using this product, I’m a believer. Highly recommend!”

Sam Brown

“I can’t imagine my life without this product. It’s a game-changer.”



var index = 0;
var testimonials = document.getElementsByClassName(“testimonial”);
var buttons = document.getElementsByClassName(“button”);

function showTestimonial(idx) {
for (var i = 0; i < testimonials.length; i++) {
testimonials[i].classList.remove("active");
buttons[i].classList.remove("active");
}

testimonials[idx].classList.add("active");
buttons[idx].classList.add("active");
index = idx;
}

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@codeandcreate
10 months ago