取消 MuiTreeItem-group 的 margin-left 怎么做?

huangapple go评论75阅读模式
英文:

how to cancel MuiTreeItem-group margin-left?

问题

I am using MUI tree, and I want to cancel the margin-left of the second layer of MuiTreeItem-group.

I tried to use makeStyles to solve it, but it doesn't seem to work.

const useStyles = makeStyles(() => ({
  root: {
    ".MuiCollapse-root .MuiCollapse-vertical .MuiTreeItem-group": {
      marginLeft: '0px',
    },
  }
}))

Then I try to use @global to modify, but it will cause other layers to be modified together.

const useStyles = makeStyles(() => ({
  root: {
   
    "@global": {
      ".MuiTreeItem-group": {
        marginLeft: '0px'
      }
    }
  }
}))

The effect I hope is that only the second layer can be modified.

英文:

i am using MUI tree,and i want to cancel the margin-left of the second layer of MuiTreeItem-group

I tried to use makeStyles to solve it, but it doesn't seem to work

const useStyles = makeStyles(() => ({
  root: {
    ".MuiCollapse-root .MuiCollapse-vertical .MuiTreeItem-group": {
      marginLeft: '0px',
    },
  }
}))

Then I try to use @global to modify, but it will cause other layers to be modified together

const useStyles = makeStyles(() => ({
  root: {
   
    "@global": {
      ".MuiTreeItem-group": {
        marginLeft: '0px'
      }
    }
  }
}))

取消 MuiTreeItem-group 的 margin-left 怎么做?

The effect I hope is that only the second layer can be modified

取消 MuiTreeItem-group 的 margin-left 怎么做?

答案1

得分: 1

你可以使用 CSS子组合器 直接定位第二级,以去除.MuiTreeItem-group的左边距。例如:

const useStyles = makeStyles(() => ({
  root: {
    "& > .MuiTreeItem-root > .MuiTreeItem-group": {
      marginLeft: "0px"
    }
  }
}));

这将产生以下效果:
取消 MuiTreeItem-group 的 margin-left 怎么做?

工作中的 CodeSandbox 链接:https://codesandbox.io/s/material-demo-forked-rhn5xf?file=/demo.tsx:307-445

英文:

You can remove the .MuiTreeItem-group left margin by using the CSS child combinator to directly target the second level. For example:

const useStyles = makeStyles(() => ({
  root: {
    "& > .MuiTreeItem-root > .MuiTreeItem-group": {
      marginLeft: "0px"
    }
  }
}));

Which would produce the following effect:
取消 MuiTreeItem-group 的 margin-left 怎么做?

Working CodeSandbox: https://codesandbox.io/s/material-demo-forked-rhn5xf?file=/demo.tsx:307-445

huangapple
  • 本文由 发表于 2023年6月12日 11:23:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453472.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定