Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

517
Vistas
MUI Carousel not displaying properly

I'm trying to make a Carousel that works with MUI components which the one I found is this one react-material-ui-carousel, but for some reason is not working properly (or maybe as usual I'm doing something wrong)

So this is what I have (and it works)

import React from 'react'
import Carousel from 'react-material-ui-carousel'
import { Card } from '@mui/material'
import CardMedia from '@mui/material/CardMedia';
import CityA from "./Images/CityA.jpg"
import CityB from "./Images/CityB.jpg"

function Item(props)
{
    return (
        <Card sx={{ width: "50%"}}>
          <CardMedia
        component="img"
        height="25%"
        image={props.item.img}
      />
        </Card>
    )
}

function Home() {

  var items = [
    {
        img: CityA
    },
    {
      img: CityB
    }
  ]

    return (
     <Carousel >
            {items.map( (item, i) => <Item key={i} item={item} />)}
     </Carousel>
    )
}

export default Home

This is the output of that code alone:

enter image description here

As you can see the it is working all good however if I try to add it as a part of my "Route" it breaks horribly

import React, { useEffect, useState } from "react";
import {BrowserRouter as Router, Routes, Route } from "react-router-dom"
import Header from "./Header";
import Home from "./Home";

function App() {
  return (
    < div className="app" >
    <Router>
        <Routes>

          <Route path = "/" element={<Header/>}>
            <Route path = "/" element = {<Home/>} />
          </Route>
          
        </Routes>
    </Router>
  </div >
  );
}

export default App;

it then looks like this:

enter image description here

Super Small! even with 500% Zoom! like what just happened! any help/tip or even other method is welcome all I wanted to do was an image carousel :c

Working demo here -> Demo

What I would like to achieve ->

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Don't set the size of the element on the element itself, set the size of the container of that element.

For example:

<OuterBox sx={{display: "flex", justifyContent: "center", flexGrow: 1}}>
   <InnerBox sx={{ width: "50%"}}>
      <ContainedElement />
   </InnerBox>
</OuterBox>

This will give you a horizontally centered element and you can resize the InnerBox to change the size of the element. The inner box takes up 50% of the space of the outer box and your contained element takes up 100% of that space

Also your routes are strange you wrote:

<Route path = "/" element={<Header/>}>
   <Route path = "/" element = {<Home/>} />
</Route>

but that means your default path is going to two different elements. I would try:

<Route path="/header" element={<Header />} />
<Route path="/" element={<Home />} />

Also for the Carousel:

function Item(props) {

   return (
   <Box sx={{display: "flex", justifyContent: "center">
     <Card width: "50%">
        <CardMedia
          component="img"
          image={props.item.img}
        />
     </Card>
   </Box>
  )
}

function Home() {
   var items = [
    {
      img: CityA
    },
    {
      img: CityB
    }
  ]

   return (
     <Carousel>
       {items.map(( (item, i) => <Item key={i} item={item} />)}
     </Carousel>
   )


}

That should work but I'm not sure about the original size of the images. Hope that helps.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda