跳转到主要内容

颜色控制

Elementor 颜色控件显示一个带有 Alpha 通道滑块的颜色选择器字段。它包含一个可由用户预设的自定义调色板。

该控件在继承 Base_Data_Control 类的 Control_Color 类中定义。

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

参数

名称 类型 默认值 描述
type string color 控件的类型。
label string 显示在字段上方的标签。
description string 显示在字段下方的描述。
show_label bool true 是否显示标签。
label_block bool false 是否在单独一行显示标签。
separator string default 设置控件分隔符的位置。可用值为 default、before 和 after。default 将隐藏分隔符,除非控件类型有特定的分隔符设置。before / after 将分隔符定位在控件之前/之后。
alpha bool true 是否允许 Alpha 通道。
default string 默认颜色,格式为 RGB、RGBA 或 HEX。

Return Value

(string) The color value in RGB, RGBA, or HEX format.

Usage

<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {

	protected function register_controls(): void {

		$this->start_controls_section(
			'style_section',
			[
				'label' => esc_html__( 'Style', 'textdomain' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'text_color',
			[
				'label' => esc_html__( 'Text Color', 'textdomain' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .your-class' => 'color: {{VALUE}}',
				],
			]
		);

		$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
	}

}

说明

了解如何在颜色控件上使用全局颜色,该设置在站点设置面板中。