const StyledTableCell = styled(TableCell)(({ theme }) => ({…
- User
const StyledTableCell = styled(TableCell)(({ theme }) => ({ [
&.${tableCellClasses.head}]: { backgroundColor: theme.palette.common.white, color: theme.palette.grey, }, [&.${tableCellClasses.body}]: { fontSize: 14, }, }));How can I add a top and bottom border to the head of this component?
I'm using MUI 5.12
- Assistant
To add a top and bottom border to the head of the
StyledTableCellcomponent, you can modify the CSS using theborderTopandborderBottomproperties. Here's the updated code:codeconst StyledTableCell = styled(TableCell)(({ theme }) => ({ [`&.${tableCellClasses.head}`]: { backgroundColor: theme.palette.common.white, color: theme.palette.grey, borderTop: `1px solid ${theme.palette.divider}`, borderBottom: `1px solid ${theme.palette.divider}`, }, [`&.${tableCellClasses.body}`]: { fontSize: 14, }, }));In the above code, we added the
borderTopandborderBottomproperties to the&.${tableCellClasses.head}selector. We also used thetheme.palette.dividerproperty to set the color of the border to match the divider color used in the theme. - User
Doesn't work
- Assistant
Sorry that the previous solution did not work for you. Another way to add a top and bottom border to the head of the
StyledTableCellcomponent is to use theborderCSS property along with theoutlineproperty to prevent double borders from appearing. Here's the updated code:codeconst StyledTableCell = styled(TableCell)(({ theme }) => ({ [`&.${tableCellClasses.head}`]: { backgroundColor: theme.palette.common.white, color: theme.palette.grey, border: `1px solid ${theme.palette.divider}`, borderBottom: 'none', outline: 'none', }, [`&.${tableCellClasses.body}`]: { fontSize: 14, }, }));In the above code, we set the
borderproperty to have a width of1px, a style ofsolid, and a color oftheme.palette.divider. We also added theborderBottomproperty and set it to'none'to remove the bottom border. Theoutlineproperty is used to remove the dotted outline that appears around the table header.