Last updated on October 18, 2023

Elementor column width problem

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Adjust Elementor column widths with ease.

The Elementor page builder allows you to create beautiful and responsive layouts for your WordPress website. However, sometimes you may encounter issues with the column width in Elementor. One common problem is when the columns do not align properly or have unequal widths.

To fix this issue, you can use custom CSS to adjust the column widths in Elementor. Here’s an example of how you can do this:

/* Adjust column widths in Elementor */
.wpsnippets_elementor-column {
    flex-basis: 0;
    flex-grow: 1;
    max-width: 100%;
}

This CSS snippet targets the Elementor column element and sets the flex-basis, flex-grow, and max-width properties to ensure that the columns have equal widths and adjust responsively.

To use this code, you can add it to your theme’s stylesheet or use a custom CSS plugin. Once added, the column widths in Elementor should be adjusted according to the CSS rules specified.

This code snippet can be useful when you want to ensure that the columns in your Elementor layout have equal widths and align properly. It helps to maintain a consistent and visually appealing design for your website.

Examples

Example 1: Adjusting Elementor column width using CSS

This use case demonstrates how to adjust the width of Elementor columns using CSS. By targeting the specific column class and adjusting its width property, you can customize the column width to your desired value.

/* Adjust the width of a specific Elementor column */
.elementor-column-33 {
    width: 50%;
}

In this example, the CSS code targets a specific Elementor column with the class .elementor-column-33 and sets its width to 50%. You can modify the class selector and width value according to your requirements.

Example 2: Adjusting Elementor column width using PHP

This use case demonstrates how to adjust the width of Elementor columns programmatically using PHP. By utilizing the elementor/element/column/layout/before_section_end action hook, you can modify the column width dynamically.

/**
 * Adjust the width of an Elementor column programmatically.
 */
function wpsnippets_adjust_elementor_column_width( $element ) {
    if ( 'column' === $element->get_name() ) {
        $settings = $element->get_settings();
        $settings['width'] = 50;
        $element->set_settings( $settings );
    }
}
add_action( 'elementor/element/column/layout/before_section_end', 'wpsnippets_adjust_elementor_column_width' );

In this example, the PHP code hooks into the elementor/element/column/layout/before_section_end action and adjusts the column width to 50%. You can modify the width value as per your requirements.

Example 3: Adjusting Elementor column width using Elementor API

This use case demonstrates how to adjust the width of Elementor columns using the Elementor API. By utilizing the update_control method of the Controls_Manager class, you can modify the column width through the Elementor interface.

/**
 * Adjust the width of an Elementor column using Elementor API.
 */
function wpsnippets_adjust_elementor_column_width( $element ) {
    $element->update_control(
        'width',
        [
            'default' => 50,
        ]
    );
}
add_action( 'elementor/element/column/section_advanced/after_section_end', 'wpsnippets_adjust_elementor_column_width' );

In this example, the PHP code hooks into the elementor/element/column/section_advanced/after_section_end action and updates the width control with a default value of 50. You can modify the default value according to your needs.

Last updated on October 18, 2023. Originally posted on October 24, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *