Search code examples
reactjsmaterial-uistyled-componentsmui-x

ReactJs Styled Components: Set Font Weight of Table Cell


Using React 18, and latest styledcomponents, how do I set the font weight for MUI Table Cell?

This code is getting the right color, but not setting font weight.

const StyledTableCell = styled(TableCell)({
  backgroundColor: "#99D9EA",
  fontWeight: "800",
});

<StyledTableCell>Enrollment Date</StyledTableCell>

enter image description here


Solution

  • Try something like:

    const StyledTableCell = styled(TableCell)({
      "& .MuiTableCell-head": {  // or "& .MuiTableCell-root" or "& .MuiTableCell-body" ...
        backgroundColor: "#99D9EA",   
        fontWeight: 800,
      }  
    });   
    

    Possible CSS classes are described here: https://mui.com/material-ui/api/table-cell/