You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何去除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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 20:18:20