Utilizing the Swiper Library for my carousel creation, I am striving to centrally position my card element but encountering difficulty in achieving this

I'm currently using the Swiper Library to create a carousel. I'm having trouble centering my card element in the middle of the screen. Below is an important snippet of code for the component that I need help with. I am utilizing styled components with the Swiper library.

const Wrapper = styled(motion.div)`
  height: 200px;
  min-width: 300px;
  width: 300px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  position: relative;

  &:hover ${Desc} {
    transform: translateY(0%);
  }
`;

const Card = () => {
  return (
    <Swiper pagination={true} modules={[Pagination]}>
      {sliderItems.map((item) => {
        return (
          <SwiperSlide key={item.id}>
            <Wrapper>
              <Title>{item.title}</Title>
              <Desc>{item.desc}</Desc>
              <Img src={item.img} />
            </Wrapper>
          </SwiperSlide>
        );
      })}
    </Swiper>
  );
};

Why is my Wrapper div taking up extra space causing the next element not to be visible on the screen?

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

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

Answer №1

To ensure the card element is centered within its parent, you can utilize the justify-self: center; property if the parent element is a grid. Alternatively, you may also consider:

margin: 0 auto;

If you prefer to center the element absolutely, you can use the following code:

position: absolute; 
top: 50%; 
left: 50%; 
transform: translate(-50%, -50%);

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

Geolocation ranking in Elasticsearch

I am experiencing constant errors with sorting in my elasticsearch query. The query is shown below: query { "query": { "bool": { "filter": { "geo_distance": { ...

Sails.js navigating through sessions

What is a rolling session in Sails.js? A rolling session is a session that expires after a set amount of time without user activity, except for websockets live updating data. If the user navigates to a different part of the site before the session expires, ...

Delete the top part of an ArrowHelper in Three.js

Within my code, I have implemented an ArrowHelper and its parameters are updated through the function below (each invocation of this function adjusts the ArrowHelper's dimensions): function updateArrowHelper() { // Update parameters for transpor ...

The Art of Receiving Feedback in THREE.js

I have created a feedback loop using backbuffer in my code with the following implementation: function render() { renderer.setRenderTarget(BufferA); renderer.render(BufferAScene, camera); renderer.setRenderTarget(null); rendere ...

Proper positioning of popover ensures it does not exceed the boundaries of its parent

In my ngprime table, the header row contains a column field with a popover set to display at the top. However, it is covering the actual field instead of appearing above it. This issue arises because the popover cannot display outside of its parent div, ca ...

What is the best way to send a variable from my controller to the HTML and then to a JavaScript function?

After my controller runs its course, it finally outputs the following: res.render('my-html', { title: `${title}`, myVar1, myVar2 }); Once this data is rendered in the HTML, I am able to directly display it. However, my goal is to then pass thes ...

Manipulating elements on the webpage and customizing the appearance for validating forms in the

To automatically display an error message next to the input field when submitting a form without any data or with incorrect email parameters, I am using local DOM manipulation with HTML, CSS, and JS. Unfortunately, I keep encountering an error: Uncaught Ty ...

Having trouble accessing the value of an item in a dropdown box on a website

I am currently developing a webpage using HTML5 and Knockout Js. I am facing an issue where I am unable to retrieve the ID of the selected item from a dropdown box in order to insert a value into an SQL table. As an example, consider the following SQL tab ...

What could be causing my component to not refresh when used as a child?

I have been experimenting with some code to track rerenders. The initial approach failed when passing <MyComponent> as a child component. it("should return the same object after parent component rerenders", async () => { jest.useF ...

How can I use jQuery to wrap multiple elements into separate divs simultaneously?

Is there a way to wrap elements individually with jQuery? I am able to wrap different divs, but they all end up wrapped in one parent div instead of separate ones. This is what I currently have: <section> <div class='parent'> ...

Exploring the world of promise testing with Jasmine Node for Javascript

I am exploring promises testing with jasmine node. Despite my test running, it indicates that there are no assertions. I have included my code below - can anyone spot the issue? The 'then' part of the code is functioning correctly, as evidenced b ...

What could be the reason behind the failure of React JS to successfully navigate users to the intended landing

I have a login page created using react jS that fetches data from a json file with the following structure: { "userName": "jjraff", "firstName": "jon", "lastName": "doe", "password": null, "token": "abc123.efg456.hijk789" } During tes ...

An issue occurred while attempting to access the `/blog` page in a next.js project

The Challenge: As I work on developing a blog using Next.js and Sanity, I am facing a browser error when trying to navigate to the /blog route. The specific error message reads as follows: ./sanity.js:2:0 Module not found: Can't resolve '@sanity ...

CSS3 Flexbox creating excess space on the right side

My website currently has a 4 column layout with each div set to a width of 25%, which is resulting in empty space on the right side. How can I adjust this layout to fill the entire screen width? https://i.sstatic.net/d0cJ6.png I have created a flexbo ...

What is the proper way to retrieve an array in the render method using React?

As someone who is still fairly new to React, I encountered a coding issue and stumbled upon this particular code snippet from a previous question (I attempted to reach out to those who had previously answered, but unfortunately, received no response as the ...

Insert a line below the active tab button

I made three buttons for three different tabs. Is there a way to include an underline below the active tab button (under the red "zone")? I'm aiming for something similar to mat-tab. Any assistance is appreciated! DEMO Code viewMode = 'tab ...

Discover the proper technique to display an error message in cases where no data is detected during the filtering process

I'm currently working on a component that involves search filtering and dropdown filtering. The filtering functionality is working fine, but I'm struggling to determine where to display an error message if no data is found during the filtering pr ...

Incorporating Data from a Dictionary into a Highcharts Series

Utilizing flask allows me to organize all my data in a dictionary for use with highcharts. my_data = { 'dataset1': {'x_values': [1, 2, 3, 4, 5, 6], 'y_values': [7, 8, 9, 10, 11, 12]}, ...

jQuery Click event not responding on the default Android Mobile Browser for anchor elements

Having trouble triggering a click event on a link element, as the title suggests. Here is the relevant part of the HTML structure: <!-- Table markup here.. --> <td class="text-center"> <a class="text-danger"><i class="fi-trash" ari ...

Upgrading Bootstrap from version 3.4 to 5.3 in a .NET project

I have a website project created using .Net Framework 4.7.2. Currently, I am utilizing Bootstrap version 3.4.1 from here. Since Bootstrap 3.4 is now in an end-of-life phase, I need to upgrade to the latest version, 5.3. Upon replacing the old version fil ...