Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
I try to override materialUI inbuilt classes using CSS file, styles are applying all the components in React how to stop overriding styles globally?

TableOne.css

 @media (min-width:601px) and (max-width: 960px) {
      .MuiTable-root  .MuiTableBody-root{
          display: flex !important;
          justify-content: center !important ;
          flex-wrap: wrap !important; 
          row-gap: 15px;
      }
    } 
**above styles are applying to all the tables present in all my React components. But I want to apply for table that present in specific component. How I can write specific .css file for specific component**
  • I am trying to access the inbuilt materialUI classes and applying styles so, styles are affecting globally how I can stop affecting styles over all the components in React JS *
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. When you write global CSS like that, it gets applied to the whole document. Instead, you can take advantage of theming in @mui/material.
  2. Use createTheme from @mui/material/styles to define the theme and ThemeProvider to apply that theme. And instead of using plain media queries, use theme breakpoints instead but you will have to specify the pixel values for these breakpoints yourself if you're not using the default ones. It can be done using theming as well.
import { createTheme } from "@mui/material/styles";
let theme = createTheme();
theme = createTheme(theme, {
  components: {
    MuiTableBody: {
      styleOverrides: {
        root: {
          "@media (min-width: 601px) and (max-width: 960px)": {
            // your styles here
          },
          [theme.breakpoints.between("md", "lg")]: {
            // use this instead
          }
        }
      }
    }
  }
});
export default theme;
  1. In your component, wrap your Table component with ThemeProvider
import Table from "./components/Table";
import { ThemeProvider } from "@mui/material/styles";
import theme from "./theme/MuiTable"; // this is the theme you created above
...
const App = props => {
  return (
    <div className="App">
      <ThemeProvider theme={theme}>
        <Table />
      </ThemeProvider>
    </div>
  );
}

Here is a working demo

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda