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

211
Visualizações
css nth-child selector doesn't work with styled mui component

I have a styled component like this:

const FormBox = styled(Box)(({ theme }) => ({
  width: "47vw",
  height: "25vh",
  backgroundColor: theme.palette.grey[100],
  borderRadius: theme.shape.borderRadius,
  marginLeft: "auto",
  marginRight: "auto",
  marginTop: theme.spacing(5),
  display: "flex",
  justifyContent: "space-between",
  flexWrap: "wrap",
  padding: theme.spacing(2),
  columnGap: theme.spacing(5),
  "&>*": { flex: "0 1 auto" },
  "&:nth-child(4)": { flex: "1 1 200px", backgroundColor: "red" }, //????????????? 
}));

in the last line of code I targeted the 4th child(the button component in the bellow code) and I want to apply some CSS on it but it doesn't work.

and inside this styled component there are four child as bellow:

<FormBox component="form" noValidate autoComplete="off">
      <TextField label="Title">{title}</TextField>
      <TextField label="Amount">{amount}</TextField>
      <LocalizationProvider dateAdapter={AdapterDateFns}>
        <DatePicker
          label="Date"
          onChange={(newValue) => {
            setDate(newValue);
          }}
          renderInput={(params) => <TextField {...params} />}
          sx={{ width: 50 }}
        />
      </LocalizationProvider>
      <Button variant="contained" sx={{height: 50}}>Add</Button>
    </FormBox>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Please try with &>*:nth-child(4) instead of &:nth-child(4).

You can make sense from this link. https://www.codegrepper.com/code-examples/css/css+selector+last+element

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