如何去除Ant Design Tree组件的左侧缩进并设置为0px?
移除Ant Design Tree组件展开节点的左侧缩进
要去掉Tree组件展开时自动添加的24px左侧缩进,直接修改你提到的.ant-tree-indent-unit类的宽度属性即可:
方法一:强制覆盖样式(简单直接)
.ant-tree-indent-unit { width: 0px !important; }
方法二:提高选择器优先级(更规范,避免!important)
给Tree组件的外层容器加一个自定义类名(比如custom-tree-container),然后用嵌套选择器覆盖样式:
.custom-tree-container .ant-tree-indent-unit { width: 0px; }
修改后,所有层级的节点展开后都不会有左侧缩进偏移。如果需要针对特定层级调整,可结合:nth-child等选择器进一步定位,但全局设置为0px基本能满足移除缩进的需求。
内容的提问来源于stack exchange,提问作者Shikha Singh
相关产品推荐
相关产品推荐

