Elementor 开发者文档

title: "尺寸控制" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Editor Controls - Src - Repos


尺寸控制

Dimensions Control

Elementor 尺寸控制显示上、右、下、左的输入字段,并提供将它们链接在一起的选项。该控件可选择包含多种单位类型 (size_units) 供用户选择。它还接受 range 参数,允许您为每种单位类型设置 minmaxstep 值。

Dimensions Control

该控件在继承 Control_Base_Units 类的 Control_Dimensions 类中定义。

使用此控件时,应将 type 设置为 \Elementor\Controls_Manager::DIMENSIONS 常量。

参数

名称 类型 默认值 描述
type string dimensions 控件的类型。
label string 显示在字段上方的标签。
description string 显示在字段下方的描述。
show_label bool true 是否显示标签。
label_block bool true 是否在单独一行显示标签。
separator string default 设置控件分隔符的位置。可用值为 defaultbeforeafterdefault 将隐藏分隔符,除非控件类型有特定的分隔符设置。before / after 会将分隔符定位在控件之前/之后。
size_units array [ 'px' ] 可用 CSS 单位的数组,例如 pxemrem%degvhcustom
default array 滑块默认值。
  • $top (int) 顶部尺寸的初始大小。
  • $right (int) 右侧尺寸的初始大小。
  • $bottom (int) 底部尺寸的初始大小。
  • $left (int) 左侧尺寸的初始大小。
  • $unit (string) CSS 单位类型的初始大小。
  • $isLinked (bool) 是否将所有值链接在一起。
placeholder array 当字段没有值时显示的占位符。
  • $top (int) 顶部尺寸的占位符。
  • $right (int) 右侧尺寸的占位符。
  • $bottom (int) 底部尺寸的占位符。
  • $left (int) 左侧尺寸的占位符。

返回值

[
    'top' => '',
    'right' => '',
    'bottom' => '',
    'left' => '',
    'unit' => '',
    'isLinked' => '',
]

(array) 包含尺寸值的数组:

Usage

```php {14-32,41-43,49-51}

start_controls_section( 'style_section', [ 'label' => esc_html__( 'Style', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'margin', [ 'label' => esc_html__( 'Margin', 'textdomain' ), 'type' => \Elementor\Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ], 'default' => [ 'top' => 2, 'right' => 0, 'bottom' => 2, 'left' => 0, 'unit' => 'em', 'isLinked' => false, ], 'selectors' => [ '{{WRAPPER}} .your-class' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); ?>
    <div class="your-class">
        ...
    </div>
    <?php
}

protected function content_template(): void {
    ?>
    <div class="your-class">
        ...
    </div>
    <?php
}

} ```