如何为古腾堡块编辑器 (WordPress) 的 InnerBlocks 模板定义默认样式
我正在使用古腾堡的核心块来使用 InnerBlock 制作另一个块。所以,我想更改它们的默认样式,例如文本对齐中心。首先,我使用官方支持的方式来创建块 创建 Guten-Block。我的代码如下:
import {
InnerBlocks, useBlockProps
} from '@wordpress/block-editor';
import './editor.scss';
export default function Edit() {
return (
<div { ...useBlockProps() }>
<InnerBlocks
template={ [
[ 'core/columns', {},
[
[ 'core/column', {}, [
[ 'core/paragraph', { content: '$200' } ],
]
],
[ 'core/column', {}, [
[ 'core/button', { placeholder : 'Buy Now' } ],
]
],
]
],
] }
templateLock="all"
/>
</div>
);
}
WordPress uses has-text-align-left class to align a text in the block. Is there any way to define default style inside the core/button's text-align to center inside the template.I am using gutenbergs' core block to make another block using InnerBlock. So, I want to change their default style like text align center.To start, I used officially supported way to create blocks Create-Guten-Block. My codes are as follows:
import {
InnerBlocks, useBlockProps
} from '@wordpress/block-editor';
import './editor.scss';
export default function Edit() {
return (
<div { ...useBlockProps() }>
<InnerBlocks
template={ [
[ 'core/columns', {},
[
[ 'core/column', {}, [
[ 'core/paragraph', { content: '$200' } ],
]
],
[ 'core/column', {}, [
[ 'core/button', { placeholder : 'Buy Now' } ],
]
],
]
],
] }
templateLock="all"
/>
</div>
);
}
WordPress uses has-text-align-left class to align a text in the block.
Is there any way to define default style inside the core/button's text-align to center inside the template.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,
core/button
块 支持对齐并且可以在InnerBlocks模板内的块属性align
中设置,例如:生成的HTML将应用内置样式
aligncenter
并且按钮现在居中对齐:Yes, the
core/button
block supports align and can be set in the block attributealign
within the InnerBlocks template, eg:The resulting HTML then has the built-in style
aligncenter
applied and the button is now center aligned: