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

如何通过theme.json为WordPress核心列表区块及列表项设置样式?

问题分析与解决方案

你的配置存在格式错误,theme.json是支持为core/list-item设置样式的,只是需要遵循正确的结构和属性名规范。

错误原因

你直接在core/list-item下定义style、indent、spacing这些属性,不符合theme.json的配置结构——所有区块的样式设置必须嵌套在styles对象内,且要使用官方规定的属性键名。

正确配置示例

{
    "settings": {
        "spacing": {
            "padding": true,
            "margin": true
        }
    },
    "styles": {
        "blocks": {
            "core/list": {
                "color": {
                    "text": "red"
                }
            },
            "core/list-item": {
                "listStyle": {
                    "type": "disc"
                },
                "spacing": {
                    "margin": {
                        "bottom": "5px"
                    },
                    "padding": {
                        "left": "2em"
                    }
                }
            }
        }
    }
}

关键说明

  • 项目符号样式:通过listStyle.type设置,可选值包括disc、circle、square、decimal等。
  • 缩进控制:用spacing.padding.left或spacing.margin.left实现,代替你写的indent键。
  • 列表项间距:通过spacing.margin.bottom设置上下间距,对应你需要的spacing: "5px"。
  • 前置要求:如果要使用spacing相关配置,需要在settings.spacing中开启padding和margin的支持,否则spacing设置不会生效。

内容的提问来源于stack exchange,提问作者Piiit

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 00:37:23