arrange both the content and slider in a single container using React Slick inline styling

I'm facing an issue with setting up a flex layout where the left section contains content and the right section contains a slider. However, despite applying flex to the main container, the slider is not being displayed.

Can anyone help me fix this problem?

App.js

import "./styles.css";
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";

export default function App() {
  return (
    <div className={"container"}>
      <div className={"user"}>Hello</div>
      <div className={"sliderSection"}>
        <Slider dots slidesToShow={3} key={item.id}>>
          {[1, 2, 3, 4].map((d) => (
            <div>{d}</div>
          ))}
        </Slider>
      </div>
    </div>
  );
}

style.css

.container {
  width: calc(100% - 194px);
  margin: 0 auto 20px auto;
  display: flex;
  border: solid 1px;
}

.user {
  width: 140px;
  height: 180px;
  background-color: red;
}

.sliderSection {
  margin-left: 30px;
}

Codesandbox Link

Answer №1

I've made some modifications in the index.css and app component. Here are the details of those changes. Please verify if it functions correctly for you.

App Component :

import "./styles.css";
import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";

export default function App() {
  return (
    <div className={"container"}>
      <div className={"user"}>Hello</div>
      <div className={"sliderSection"}>
        <Slider className={'slider'} dots slidesToShow={3}>
          {[1, 2, 3, 4].map((d) => (
            <div key={d} >{d}</div>
          ))}
        </Slider>
      </div>
    </div>

    )
  }

Css file:

.container {
  width: calc(100% - 160px);
  margin: 0 auto 20px auto;
  display: flex;
  border: solid 1px;
}

.user {
  width: calc(100% - 100px);
  height: 150px;
  background-color: blue;
}

.sliderSection {
  background-color: green;
  width: 100%;
  display : flex;
  justify-content: center;
  align-items : center;
}

.slider{
  width: 50px;
}

Note : These adjustments were made on a mobile device. You may need to adapt the sizing accordingly.

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

NextJS13 App encountering difficulty with login page verifying credentials in database

Setting up a login system for my nextJS 13 app has been quite the challenge. I managed to connect it to a Postgresql database and create a signup page using a Prisma model. Now, I'm facing difficulties with the login form as I can't seem to get ...

Ways to align an inner circle in the middle using CSS

div.container{ border:2px dashed blue; position:relative; } span.parent{ display:inline-block; width:40px; height:40px; border:2px solid black; border-radius:50%; text-align: center; position:absolute; right:20px; top:10px; } span.ch ...

Troubleshooting Token Issue in Node.Js with Jest Testing (Encountering 401 "Unauthorized" Error)

Hey there, I am currently experimenting with Jest on a Node.js project where I need to test my functions. const userOne = { _id: userOneId, name: 'Mike', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9 ...

When using PHP's `json_encode()`, don't forget to append a "1" at the

While utilizing json_encode in my project, I have encountered an issue that is perplexing. On one particular page where I make an ajax call, the resulting json seems to mysteriously add a 1 to the end of the string. The output of my return string appears ...

Can you provide me with a variable that will give me the total size of the scrollbar?

How can I determine the maximum number of pixels scrolled on a webpage? I attempted using window.pageXOffset, but it only gives the current scrolled amount. I require the total size at all times. ...

Implement dynamic changes to CSS variable values using Typescript during runtime

My angular 4 web application requires dynamic styling based on color values and image URLs received from the backend. While I have successfully set up the app to load images from the server, handling color values poses a greater challenge. The primary colo ...

What is the reason for JQuery not generating a fresh div during every loop?

I'm currently facing an issue where jQuery seems to be combining all the image divs and description divs into one container div, rather than creating individual containers for each pair in my for loop. This is causing a disruption in the overall layou ...

Node.js and Express throwing errors when trying to access a certain endpoint with HTTPS and passing parameters

I am experiencing issues with my node.js express webserver that operates on both HTTP and HTTPS, specifically related to express's route parameters and HTTPS. Express allows for parameters in the routing, such as: app.get('/users/:userid', ...

Offline access to Material UI documentation

Is it possible to access MUI documentation offline for downloading and reading? I am aware that I can construct the MUI website by utilizing their github repository, but unfortunately my laptop struggles to run smoothly. When attempting this, it experienc ...

Running a JavaScript asynchronous function and capturing the output using Selenium

Attempting to run the script below in Selenium result = driver.execute_script('let result; await axe.run().then((r)=> {result=r}); return result;') Results in an error: Javascript error: await is only valid in async function Another at ...

Once I press the button to switch all the other buttons to dark mode, it only successfully changes them once

I created a button that switches the entire page to dark mode. I also have some dark buttons that I want to switch to light when the dark mode button is clicked. The issue is that while changing the page to dark mode works, the dark buttons only toggle ...

Font formatting functions correctly on local host, but fails to load on live server

I've successfully integrated the Google font "Raleway" into my Next.js application. However, I'm facing an issue where the fonts display correctly on my local server but do not show up in the live environment after running npm build. Any advice ...

"Learn the process of toggling the visibility of multiple objects by passing props from child components to parent components and

My approach to design is quite straightforward. I have a sidebar in child components (Aside.js) and a Main object that displays content (Main.js), all of which are used in ImportPage. In Aside, I have three buttons that I want to use to show and hide conte ...

Positioned div in Bootstrap not displaying properly above navigation bar

My dropdown menu from the navbar is triggered by a toggle button. To indicate that it points to the trigger button, I added a triangle above the navbar-collapse. While this works well on larger screens, on mobile devices, it keeps getting pushed behind the ...

Users are reporting that a React application deployed on IIS on a Windows Server 2008 R2 environment is displaying a blank

I encountered a strange issue where a React application that worked fine when published on IIS on my Windows 10 PC, displayed a blank page when running on IIS on Windows Server 2008 R2. Here is an excerpt from my package.json file: { "name": & ...

Error message: jQuery expression not being detected

Here is some html code that I have in my view: <div id="divLoginName" style="display: none"> <input type="hidden" id="hidLoginName" /> @Html.TextBox("txtEditLoginName", null, new { maxlength = "1000", tabindex = "0", Multiline ...

Is it necessary to run npm install when a package does not have any dependencies?

If I have an npm package that contains all its dependencies bundled into one file using webpack, and I unpack it into the directory ./my-awesome-package/, should I still run npm install ./my-awesome-package/? I am aware of being able to specify preinstall ...

What is the best way to keep the cart icon in the navbar consistently positioned for both desktop and mobile displays?

I am currently working on customizing a Bootstrap navigation bar using CSS to ensure that the shopping cart icon remains on the right side of the bar on both desktop and mobile devices. Despite my efforts to arrange the elements in various ways, the CSS "o ...

What is the best way to align my text to the top of a div, rather than the bottom?

Currently, the text is displaying at the bottom. This is my code snippet: <div class="container"> <h1 class="text-center">Machine Learning and Development</h1> <div style="text-align: left;"> <!-- <video autoplay mu ...

JavaScript causing attribute() variable to malfunction in CSS animation

I am attempting to implement a CSS animation using three files. Below is the HTML file: <html lang="en"> <head> <link rel="stylesheet" type="text/css" class = "tag" href="../css/style.css" ...