Skip to Main Content

How to align elements on the same line on Divi

Divi: the easiest WordPress theme to use

Divi: The best WordPress theme of all time!

With over 701.000 downloads, Divi is the most popular WordPress theme in the world. It is complete, easy to use and comes with more than 62 free templates. [Recommended]

The possibility of vertically aligning the content when creating a site with Divi can be a practical addition to your design tool. Sometimes a certain layout requires that content be aligned vertically in different ways (centered, bottom, top). The most common need is to center your content vertically.

It provides a delicious touch of symmetrical spacing that comes in handy when using multiple column layouts for your content. Additionally, vertically-centered content remains centered at different browser widths, eliminating the hassle of applying custom padding or margins to achieve similar responsiveness.

In this tutorial, I'll show you how to add a few small snippets of CSS to any column to vertically align the content. I'll be using some of Divi's pre-built layouts for examples of how to do this. If you don't know much about CSS, you don't have to worry. It will be pretty easy to apply to your own layouts in seconds.

Understanding Flex and Divi

The css Flex (or Flexbox) property is simply a way to position items in horizontal and / or vertical stacks (much like a table). Except, unlike traditional tables, the flex property lets you create boxes that will adjust to the size of the content it contains.

Divi uses the flex property whenever you select “Equalize Column Heights” as the row parameter. It just ensures that the size of your columns will adjust to the size of the column with the most content. And since “Equalize Column Heights” enables flex for the row container, you can easily take advantage of it by adding css to your columns to adjust the content of each column (or area).

For example, if you add "margin: auto" to a column in a row, the content of that column (whether it is one or more modules) will become vertically centered.

In addition, if you add "align-items: center" to your line, all your columns (and their contents) will be centered vertically.

Of course, there are many other uses for the Flex property in web design, as well as more advanced CSS that you can apply to your theme. But for this tutorial, I wanted to keep it simple.

Is it really necessary?

Technically, no. You can vertically align your content / modules in a column using custom spacing (padding and margin). For example, you can use Divi's spacing options to give a column equal to the top and bottom padding to center the module (s) vertically in the column. You can also add only top padding to a column to align bottom content. However, you may need to adjust the spacing when updating your page with more content. Additionally, it can be difficult to maintain this alignment across different browser widths.

So if you're looking for a solution to vertically align content without having to think about custom spacing, I think you'll find this useful.

Let's start!

Load the predefined layout on your page

To begin with, I'll be using the layout from the Interior Design Company Portfolio range. To get this layout on your page, create a new page. Then give your page a title. Click on “Use Divi Builder” then on “Use Visual Builder”. Then select the option "Choose a basic layout". Then select the Interior Design Company layout kit from the Load from Library pop-up window. Finally, select the Portfolio page from the list of layouts and click "Use this layout".

template divi theme wordpress.png

Once the layout is loaded on your page, you are ready to go.

Method 1: How to Vertically Align Content Using Flex and Auto Margin

Open the line settings for the second line of the page (the one directly below the line with the page title). Under Design Settings, open the sizing option group and notice that "Equalize Column Heights" is already active. This means that the line now has the flex property (“display: flex;”) added.

harmonize the heights of the columns.png

Now go to the settings of the Advanced tab for the same row and add the following css snippet under the entry box of the main element of column 2.

marginauto;

automatic margin divi.png

Easily create your website with Elementor

Elementor allows you to easily create any website design with a professional look. Stop paying expensive for what you can do yourself. [Free]

Now the contents of the second column have been moved to be centered vertically.

Make lower content aligned

If you want to align your content on the bottom so that all modules stack at the bottom of your column, you can adjust the margin value as follows:

marginauto 0;

margin divi line.png

Vertical alignment of content for all columns in your row

Instead of adding "margin: auto" to each column individually, you can also vertically center the contents of all columns in your row by adding the following snippet to the main element of your row settings.

align-items: center;

align divi.png elements

Or if you want all the contents of your columns to be aligned at the bottom, you can add this excerpt:

align-items: flex-end;

And don't forget that you can take advantage of Divi's Extend Styles feature by right-clicking on the main element with your CSS snippet and clicking on "Extend main element".

extend main element.png

Then, extend this main css element to all the lines of the page (or section) to vertically center all the contents of each column of the page.

expand styles on divi.png

Now everything is centered vertically.

appearance of the divi.png changes

But, you may have noticed that the background color of the white column no longer covers the entire height of the row. This is because we added “margin: auto” to the column. To resolve this issue, you can change the background color of the line to white and remove the fill from the line. But instead, I'll show you a way to center your column content without changing the margin.

Method 2: Align content vertically using column flex direction

In the first method, we took advantage of the flex property added to the row. This made each of our columns a “flexible box” that could be aligned vertically by simply adjusting the margin.

But there is also a flex-direction way to align our column contents without losing the “Equalize Column Height” effect which keeps our columns (and column backgrounds) the same size. To do this, we'll just add a few lines of CSS to our column so that all the modules in the column are stacked vertically and then centered.

Are you looking for the best WordPress themes and plugins?

Download the best plugins and WordPress themes on Envato and easily create your website. Already more than 49.720.000 downloads. [EXCLUSIVE]

Let's go back to our line in the previous example. Open row settings and remove any custom css you may have there by right clicking on custom CSS and clicking "Reset custom CSS styles".

Then add the following CSS under the 2 column, main element:

display: flex; flex-direction: column; justify-content: center;

Steering flex-column.png

Or, if I wanted to align the content at the bottom, just replace "Justify the content: center" with "justify the content: flex-end".

flex alignment end.png

What's great about this setup is that if my content is centered vertically and the row width is reached, the content stays centered.

appearance of boxes.png

Make blurbs (Summary) with different amounts of vertically aligned text

Making your column content vertically centered can also be useful for blurbs. As you know, not all blurbs will contain the exact amount of text used to describe the feature or service. Centering these blurbs vertically can create a beautiful design for your layout.

For this example, I'll be vertically aligning the blurbs to the Digital Payments homepage layout.

I'm going to add different amounts of body text to the blurbs first to give a more realistic representation of what a site might look like.

blorbds.png alignment

Now I have to go to the line settings and "Harmonize column heights".

harmonize columns.png

Now I can add my CSS snippets to align my content and modify the design.

Under the Advanced tab of your row settings, we can vertically center the content of our columns by adding the following under Main Element:

align-items: center;

Modify content alignment divi.png

Or change it by following to line them down.

align-items: flex-end;

alignment at the bottom divi.png

Easily create your Online Store

Download free WooCommerce, the best e-commerce plugins to sell your physical and digital products on WordPress. [Recommended]

You can also reset your custom CSS styles and add the following custom margins to align the first column bottom and the third aligned column top.

1 column CSS main element:

marginauto auto 0;

3 column CSS main element:

margin0 auto auto;

customize the alignment of abstracts divi.png

What about single column layouts?

Technically, you don't need a CSS or flex snippet to vertically center your column content. All you need to do is make sure you have equal spacing above and below your content (or modules). Most of the time, users need vertical content centered on layouts with multiple columns because they want adjacent content to line up perfectly.

That's all for this tutorial which shows you how to align elements on the same line on Divi.

This article features 0 comments

Leave a comment

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

This site uses Akismet to reduce unwanted. Learn more about how your comments data is used.

Back To Top
4 shares
Share2
tweet
Save2