CSS Testimonial Slider - Customer Feedback Display

I'm having some issues with the code below:

<div id="box">
      <div class="wrapper">
        <div class="testimonial-container" id="testimonial-container">
          <div id="testimonial1" class="active">
            <img src="" />
          </div>
        </div>
        <button id="prev" onclick="prev()">&lt;</button>
        <button id="next" onclick="next()">&gt;</button>
      </div>
    </div>
#box {
  position: relative;


    width: auto;
  left: auto;
  margin: auto;
    max-width: 70em;
    min-height: 26em;
    max-height: 70em;





}
.img-con {
    position: absolute;
}
.img-con img {
    height: 1px;
    width: 1px;
}

.testimonial-container {


  margin-top: 1%;
    width: 85%;
    height: 100%;
    position: relative;
    margin: auto;
    padding: 1.8em 1.2em;


}
.testimonial-container p {
    color: #8c8c90;
    text-align: center;
    font-size: 0.9em;
    line-height: 2em;
    letter-spacing: 0.05em;
}
.testimonial-container img {
    display: block;
    margin: 1.8em auto 1.25em auto;
    border-radius: 50%;
    width: 4.4em;
}
.testimonial-container h3 {
    color: #2d3d67;
    font-size: 1em;
    text-align: center;
}
.testimonial-container h6 {
    color: #bcc4da;
    font-size: 0.9em;
    letter-spacing: 0.03em;
    font-weight: 400;
    text-align: center;
}
.wrapper button {
    font-size: 1.8em;
    color: #0a69ed;
    height: 2.2em;
    width: 2.2em;
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    background-color: #ffffff;
    border: none;
    border-radius: 50%;
    -webkit-box-shadow: 0 0 1em rgba(0, 0, 0, 0.25);
    box-shadow: 0 0 1em rgba(0, 0, 0, 0.25);
    cursor: pointer;
}
button#next {
    right: -1.1em;
}
button#prev {
    left: -1.1em;
}

@media screen and (max-width: 650px) {
    .wrapper {
        font-size: 14px;
    }
}
window.addEventListener("load", function() {
  document.getElementById("loader").style.display = "none";
  document.getElementById("box").style.display = "block";
});
const testimonials = [
  {
    name: "example",
    job: "example",
    image: "https://static-exp1.licdn.com/sc/h/244xhbkr7g40x6bsu4gi6q4ry",
    testimonial:
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et erat arcu. Quisque mi quam, accumsan non sagittis vitae, sodales ut elit. Donec a magna ut leo eleifend dapibus. Curabitur semper placerat fringilla. Suspendisse potenti. Suspendisse pretium elit vel vulputate varius. "
  },
  {
    name: "example",
    job: "example",
    image: "https://static-exp1.licdn.com/sc/h/244xhbkr7g40x6bsu4gi6q4ry",
    testimonial:
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et erat arcu. Quisque mi quam, accumsan non sagittis vitae, sodales ut elit. Donec a magna ut leo eleifend dapibus. Curabitur semper placerat fringilla. Suspendisse potenti. Suspendisse pretium elit vel vulputate varius. "
  },
  {
    name: "example",
    job: "example",
    image: "https://static-exp1.licdn.com/sc/h/244xhbkr7g40x6bsu4gi6q4ry",
    testimonial:
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et erat arcu. Quisque mi quam, accumsan non sagittis vitae, sodales ut elit. Donec a magna ut leo eleifend dapibus. Curabitur semper placerat fringilla. Suspendisse potenti. Suspendisse pretium elit vel vulputate varius. "
  }
];
let f = 0; // current slide
let j = testimonials.length; // total slides
let testimonialContainer = document.getElementById("testimonial-container");
function next() {
  f = (j + f + 1) % j;
  displayTestimonial();
}

function prev() {
  f = (j + f - 1) % j;
  displayTestimonial();
}
let displayTestimonial = () => {
  testimonialContainer.innerHTML = `
        <p>${testimonials[f].testimonial}</p>
         <img src=${testimonials[f].image}></img>
        <h3>${testimonials[f].name}</h3>
        <h6>${testimonials[f].job}</h6>
        `;
};
window.onload = displayTestimonial;

When I run this code, it's cutting out the button at the end, instead of displaying as expected. Here is how it currently looks:

https://i.sstatic.net/Nw5jx.png

I suspect the issue lies within the #box section, but changing the width to auto doesn't seem to fix it. Can someone help me identify the problem and provide a solution? Thank you.

Tried adjusting the width of #box, but it didn't make any difference. I believe the issue originates from within #box, but I'm unsure which part specifically affects it, given that setting width: auto doesn't resolve the problem.

Answer №1

Check out my solution to this problem by visiting the link below: https://codepen.io/bozzhik/pen/bGKReqm

I approached the problem by enclosing everything in a container block and adjusting the margins to 50px

<div id="container"></div>

Here are the CSS properties I applied to the container block:

#container { margin: 50px;}

This method worked perfectly for me (this is my first time offering assistance on this platform)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling to include a CSS link to the file, but encountering failure due to a space within the path

The path to the stylesheet is located at C:\Users\abc xyz\Downloads\link-to-a-stylesheet\css. The editor highlights the section after abc in green, but unfortunately, it is not functioning as expected. ...

"Exploring the Power of Internal Hyperlinks in HTML

As I embark on my first website building journey, I am faced with a dilemma regarding internal links. While everything runs smoothly locally, none of the internal links seem to work once the site is live. Take for instance this internal link: <a href =& ...

Can importing a library generate a fresh copy of the imported library?

In my development setup using webpack and vue-loader to build a Vue.js application, I have various .vue files for different components. Whenever I include the line: import _ from 'lodash' in the script section of both ComponentA.vue and Compone ...

I'm encountering an error in my terminal while running the code

ERROR *Server started on port 4000 Database ErrorMongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 (node:1616) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 at NativeConnection.Connec ...

Resolving the "Error: Cannot update a React state on an unmounted component" issue

I encountered a console error while attempting to navigate to a new page within my web application. Here's the error message I received: Warning: A React state update was attempted on an unmounted component, which is essentially a no-op. However, t ...

Converting JSON data to an Excel file in an Angular application

I'm working on exporting my JSON data to an XLSX file. Despite successfully exporting it, the format in the Excel file isn't quite right. Below is the code I am using: downloadFile() { let Obj = { "data": [12,123], "date": ["2018-10- ...

Turn off images using Selenium Python

In order to speed up the process, I believe that disabling images, CSS, and JavaScript can help since Webdriver waits for the entire page to load before moving on. from selenium import webdriver from selenium.webdriver.firefox.firefox_profile import Firef ...

Adding up the values of an array of objects by month using ReactJS

To start off, I'm using ChartJS and need to create an array of months. Here's how it looks: const [generatedMonths, setGeneratedMonths] = useState<string[]>([]) const [totalValues, setTotalValues] = useState<number[]>([]) const month ...

Change the date string to year, month, and day

When using Ajax's getResponseHeader("Last-Modified"), it returns a date string with the format displayed below: Thu Oct 13 2016 13:05:17 GMT+0200 (Paris, Madrid, sommartid) I am wondering if it is achievable in javascript to extract the year, month, ...

Adjust the position of an image to move it closer to the top using CSS

I have a fiddle where I am trying to adjust the position of an image (keyboard) to match a specific design. https://i.sstatic.net/flqCH.png In my fiddle, the keyboard image is slightly lower than the desired position shown in the design. I am looking for ...

Stylish CSS for your website's navigation

I am facing a challenge with creating a menu for my website. I want it to be positioned on the left side, similar to the image provided below. However, despite writing the code and applying styles as expected, the menu does not display correctly and appear ...

How to Target HTML Tags Locally using CSS Modules in Next.js?

I am looking to implement smooth scrolling specifically on one page in my Next.js application, such as my blog. Instead of applying it to the entire site through the globals.css file, I need a way to inject scroll-behavior: smooth; into the html tag only f ...

Switch div and expand/shrink the rest

Apologies for what might seem like a trivial question, but after working for a few hours now, I'm finding it difficult to wrap my head around this. My initial instinct is to handle this by manipulating the entire div structure with JavaScript, but I c ...

Why won't the div move when I click it?

Could you please explain why my JavaScript code isn't functioning as expected? The intended behavior is for the 'mark' div to move to the current mouse coordinates upon clicking within the map. ...

How to dynamically delete React Router Link components after they have been clicked on?

When using React Router, how do I remove the div that contains a Link component or the Link component itself when it is clicked on and the routing is complete? For instance, consider an app structured in the following way: ==Header== ==Link1 Link2== Onc ...

Maximizing the Potential of SSJS ContinueRequest

Is there a way to incorporate ContinueRequest into the script shown below in order to bypass the 2500 limit? <script runat="server"> Platform.Load("Core","1"); try { var DEkey = Request.GetQueryStringParameter(&qu ...

Rendering sibling components on Multiple Select Material UI in React

Here is my current challenge: I am trying to implement a multiple select feature with checkboxes in React using Material UI. The desired outcome should resemble the image linked below: https://i.stack.imgur.com/TJl8L.png I have structured my data in an a ...

Is there a way for me to extract a smaller segment from an ID label?

I am working on a web development project and I have a set of buttons within a specific section. Each button has an id in the format of #balls-left-n, where n ranges from 1 to 15. My goal is that when a user clicks on one of these buttons, I want to extra ...

Determining the best use-case for a React framework like Next or Gatsby versus opting for Create React App

As I delve into the world of React and JavaScript, I find myself in the fast-paced prototyping stage. I can't help but ponder at what point developers choose to utilize frameworks like Next.js or Gatsby.js over the usual Create React App. I'm pa ...

Obtain the index of a selected option in a Select Tag using Node.js/Express

When you make a POST request with a form in Node.js/Express For example: <select name="selectname"> <option value="value1">Value 1</option> <option value="value2" selected>Value 2</option> <option value="value3"> ...