Divi comes with a wide array of column structures for beautiful desktop designs. In this tutorial, we are going to unlock these flexible column layouts for mobile devices (phone and tablet) as well using responsive CSS grid.
Do you you miss the flexible Divi row layout options when designing for mobile? I sure do, so I decided to create a CSS grid system that allows custom column structures in ALL devices. In this tutorial, we are going to apply both equal width column structures as well as mixed column widths combinations. You don’t need any plugins and it works flawless in all modern web browsers. I hope that you will enjoy this brand new toolbox for responsive row design in Divi!
Join +4 730 subscribers!
Table of Contents
- The result: Our custom column layouts library
- Before we start: Why you’ll see an error message in backend and why you should ignore it
- Step 1. Add CSS for custom mobile column structures in Divi
- Step 2. Add CSS Classes to your Divi Rows to change the number of columns on mobile and tablet
- Bonus #1: Vertically centering the columns
- Bonus #2: Make “widow columns” full width
- Frequently Asked Questions About CSS Grid
Off we go!
The result: Our custom column layouts library
Here are the new responsive column structures that we are going to unlock for phones and tablets.
Mixed Column Widths (Mobile & Tablet)
- 2 columns (1/3 + 2/3)
- 2 columns (2/3 + 1/3)
- 2 columns (1/4 + 3/4)
- 2 columns (3/4 + 1/4)
- 3 columns (2/4 + 1/4 + 1/4)
- 3 columns (1/4 + 1/4 + 2/4)
- 3 columns (1/4 + 2/4 + 1/4)
Do you miss a specific column structure in the list? Let me know in the comments below and I’ll see what I can do.
Before we start: Why you’ll see an error message in backend and why you should ignore it
When you add the CSS below in the Divi Theme Customizer, you will see an error message stating:
There are X errors which must be fixed before you can save.
So am I trying to break your site or what? Of course not, this CSS code works perfect in Divi and it’s supported by all modern web browsers. If you test it in the W3C CSS Validator tool, you’ll get a perfect score:
The World Wide Web Consortium (W3C) develops standards and guidelines to help everyone build a web based on the principles of accessibility, internationalization, privacy and security.
The reason that you will see the warning in the Theme Customizer is that WordPress uses an obsolete validation service called CodeMirror that hasn’t been updated with the latest CSS standards. The false warning is about the CSS grid unit “fr” (fraction) which works flawless with WordPress and Divi. This fact has been discussed in the official Divi Theme Users Facebook group:
“Resolved: This is caused by a deprecated code called CodeMirror, which is included as part of WordPress. It’s WordPress, not Divi, that has to replace CodeMirror. WordPress is already aware.”
How to bypass the false error message
So to go on and unlock the custom column structures in Divi, simply tick the checkbox “Update anyway, even though it might break your site?” and click “Publish”. Nothing bad will happen, I promise. This is also the recommended solution provided by the Elegant Themes support:
“It shows the error as WordPress doesn’t recognize it but it works fine on the front-end so you can ignore it.”
Step 1. Add CSS for custom mobile column structures in Divi
Let’s begin! First you need to add some custom CSS to unlock the custom mobile row structures in Divi.
- Log in to your WordPress dashboard
- Go to Divi » Theme Customizer » Additional CSS
- Copy and paste the CSS below:
/*** Custom Divi Row Structures For Mobile Devices By VictorDuse.com ***/ /* Global CSS */ @media screen and (max-width: 980px) { html .et-db #et-boc .dm-row { display: grid; } html .et-db #et-boc .dm-row.et_pb_row:after { content:none; } html .et-db #et-boc .dm-row .et_pb_column { margin-right: 0; width: auto; margin-bottom:0; } } /* Set GAP size between columns for phone devices */ @media screen and (max-width: 767px) { .dm-row { gap: 15px; } } /* Set GAP size between columns for tablet devices */ @media screen and (max-width: 980px) and (min-width: 768px) { .dm-row { gap: 20px; } } /* Two equal columns mobile */ @media screen and (max-width: 767px) { .dm-2-col-mob { grid-template-columns: repeat(2, 1fr); } } /* Two equal columns tablet */ @media screen and (max-width: 980px) and (min-width: 768px) { .dm-2-col-tab { grid-template-columns: repeat(2, 1fr); } } /* Three equal columns mobile */ @media screen and (max-width: 767px) { .dm-3-col-mob { grid-template-columns: repeat(3, 1fr); } } /* Three equal columns tablet */ @media screen and (max-width: 980px) and (min-width: 768px) { .dm-3-col-tab { grid-template-columns: repeat(3, 1fr); } } /* Four equal columns mobile */ @media screen and (max-width: 767px) { .dm-4-col-mob { grid-template-columns: repeat(4, 1fr); } } /* Four equal columns tablet */ @media screen and (max-width: 980px) and (min-width: 768px) { .dm-4-col-tab { grid-template-columns: repeat(4, 1fr); } } /* Five equal columns mobile */ @media screen and (max-width: 767px) { .dm-5-col-mob { grid-template-columns: repeat(5, 1fr); } } /* Five equal columns tablet */ @media screen and (max-width: 980px) and (min-width: 768px) { .dm-5-col-tab { grid-template-columns: repeat(5, 1fr); } } /* Six equal columns mobile */ @media screen and (max-width: 767px) { .dm-6-col-mob { grid-template-columns: repeat(6, 1fr); } } /* Six equal columns tablet */ @media screen and (max-width: 980px) and (min-width: 768px) { .dm-6-col-tab { grid-template-columns: repeat(6, 1fr); } } /* 2 columns 1/3 and 2/3 phone */ @media screen and (max-width: 767px) { .dm-2-col-1-2-mob { grid-template-columns: 1fr 2fr; } } /* 2 columns 2/3 and 1/3 phone */ @media screen and (max-width: 767px) { .dm-2-col-2-1-mob { grid-template-columns: 2fr 1fr; } } /* 2 columns 1/4 and 3/4 phone */ @media screen and (max-width: 767px) { .dm-2-col-1-3-mob { grid-template-columns: 1fr 3fr; } } /* 2 columns 3/4 and 1/4 phone */ @media screen and (max-width: 767px) { .dm-2-col-3-1-mob { grid-template-columns: 3fr 1fr; } } /* 2 columns 1/3 and 2/3 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-2-col-1-2-tab { grid-template-columns: 1fr 2fr; } } /* 2 columns 2/3 and 1/3 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-2-col-2-1-tab { grid-template-columns: 2fr 1fr; } } /* 2 columns 1/4 and 3/4 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-2-col-1-3-tab { grid-template-columns: 1fr 3fr; } } /* 2 columns 3/4 and 1/4 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-2-col-3-1-tab { grid-template-columns: 3fr 1fr; } } /* 3 columns 1/4 and 1/4 and 2/4 phone */ @media screen and (max-width: 767px) { .dm-3-col-1-1-2-mob { grid-template-columns: 2fr 2fr 4fr; } } /* 3 columns 2/4 and 1/4 and 1/4 phone */ @media screen and (max-width: 767px) { .dm-3-col-2-1-1-mob { grid-template-columns: 4fr 2fr 2fr; } } /* 3 columns 1/4 and 2/4 and 1/4 phone */ @media screen and (max-width: 767px) { .dm-3-col-1-2-1-mob { grid-template-columns: 2fr 4fr 2fr; } } /* 3 columns 1/4 and 1/4 and 2/4 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-3-col-1-1-2-tab { grid-template-columns: 2fr 2fr 4fr; } } /* 3 columns 2/4 and 1/4 and 1/4 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-3-col-2-1-1-tab { grid-template-columns: 4fr 2fr 2fr; } } /* 3 columns 1/4 and 2/4 and 1/4 tablet */ @media screen and (min-width: 768px) and (max-width: 980px) { .dm-3-col-1-2-1-tab { grid-template-columns: 2fr 4fr 2fr; } }
- Tick the checkbox beside the false error message “Update anyway, even though it might break your site?”. It will not break your site in any way, shape or form.
- Click the blue Publish button to save the CSS.
Copy the entire CSS snippet to unlock all the additional column structures for mobile and tablet.
Step 2. Add CSS Classes to your Divi Rows to change the number of columns on mobile and tablet
To apply the new column structure for mobile and tablet you need to add the matching CSS class(es) to your Divi row.
- Enable the Divi Visual Builder on the page that you want to edit
- Edit the row (that’s the box with the green border) by clicking the cogwheel
- Go to Advanced » CSS ID & Classes » CSS Class
- Add the CSS class dm-row and then add one or two more CSS classes, matching the column structure that you want to use, from the list below. Separate the class names with a single space.
The CSS classes should always start with dm-row since that class adds the general grid properties needed. Confused? See the example further below.
Mixed width columns
Phone CSS class
Tablet CSS class
Two (1⁄3 + 2⁄3)
dm-2-col-1-2-mob
dm-2-col-1-2-tab
Two (2⁄3 + 1⁄3)
dm-2-col-2-1-mob
dm-2-col-2-1-tab
Two (1⁄4 + 3⁄4)
dm-2-col-1-3-mob
dm-2-col-1-3-tab
Two (3⁄4 + 1⁄4)
dm-2-col-3-1-mob
dm-2-col-3-1-tab
Three (1⁄4 + 1⁄4 + 2⁄4)
dm-3-col-1-1-2-mob
dm-3-col-1-1-2-tab
Three (2⁄4 + 1⁄4 + 1⁄4)
dm-3-col-2-1-1-mob
dm-3-col-2-1-1-tab
Three (1⁄4 + 2⁄4 + 1⁄4)
dm-3-col-1-2-1-mob
dm-3-col-1-2-1-tab
Start by adding the class dm-row and then add one or two additional classes to your row settings. Separate the class names with simple spaces, for example: dm-row dm-2-col-1-2-mob dm-2-col-3-1-tab
Equal width columns
Phone CSS class
Tablet CSS class
Two
dm-2-col-mob
dm-2-col-tab
Three
dm-3-col-mob
dm-3-col-tab
Four
dm-4-col-mob
dm-4-col-tab
Five
dm-5-col-mob
dm-5-col-tab
Six
dm-6-col-mob
dm-6-col-tab
Start by adding the class dm-row and then add one or two classes to your row settings. Separate the class names with a simple spaces, for example: dm-row dm-2-col-mob dm-4-col-tab
Please notice: In some backend previews, like in the Divi Theme Customizer preview, the column structure is not always displayed 100% accurate. Save and preview in frontend to see the final result. Clear your browser cache and website cache if the new row structure doesn’t display.
One example on how to use the CSS classes
💡 Pro tip: Just change the values gap: 15px (for phones) and gap: 25px (for tablets) in the beginning of CSS code to adjust the spacing between the columns. The CSS grid gap value is similar to the “gutter width” option in the Divi Visual Builder settings for desktop rows.
Bonus #1: Vertically centering the columns
Okey, so the columns are now displayed side by side in mobile devices. But what if you want to vertically center-align the columns? Easy peasy!
- Click the cogwheel to open the row settings
- Go to Advanced » Custom CSS
- Add the CSS below in the Main Element field for tablet and/or phone:
align-items: center;
That’s it! Save and preview in frontend. I’ve added a black background to each single column in the example below to highlight the effect:
Bonus #2: Make “widow columns” full width
Let’s say that your original desktop row has three columns. If you apply the two columns on phone class dm-2-col-mob to this row, it will display two 50% wide columns side by side and the third column below which will also be 50% wide (see the example image below).
Often this is fine but in some cases, you might want to stretch the last “widow column” to cover the full width of the row. Here’s how to do just that:
- Click the cogwheel to open the row settings
- Click the cogwheel to open the column settings for the column that you want to stretch
- Go to Advanced » Custom CSS
- Add the CSS below in the Main Element field:
grid-column: 1 / -1;
All done! Save and preview in frontend. Make sure that you add the CSS snippet to the column settings of the column that you want to stretch – not to the row settings.
Frequently Asked Questions About CSS Grid
Are you new to CSS grid? Don’t worry, here’s a quick introduction the popular design system that every savvy web designer should know. You’ll also find some links to resources where you can sharpen your CSS skills.
What is CSS Grid, and how does it differ from Flexbox?
CSS Grid is a two-dimensional layout system in web development, while Flexbox is one-dimensional. Grid handles both rows and columns, while Flexbox manages content alignment along a single axis.
How does basic CSS grid code look like?
To begin using CSS Grid, define a container as a grid with display: grid;, set up rows and columns with properties like grid-template-rows and grid-template-columns, and position items using grid-row and grid-column.
Is CSS Grid suitable for responsive design?
Yes, CSS Grid is excellent for responsive layouts. You can use media queries to adapt grid structures, row/column sizes, and item placement to different screen sizes.
Is CSS Grid widely supported in web browsers?
CSS Grid is well-supported in modern browsers. Here’s an overview of the web browser surpport for CSS grid.
Where can I learn more about CSS grid for Divi?
The blog post How to Create a CSS Grid Layout for Divi Modules from Elegant Themes is a god starting point. CSS-Tricks offers A Complete Guide to CSS Grid. Another great source of knowledge is the CSS guru Kevin Powell’s Youtube playlist about CSS grid.
That’s all for today!
I hope that you enjoyed this post. Subscribe to VictorDuse.com on YouTube and join our Facebook group for more crisp content on WordPress and web design.
👉 Related post: How To Adjust Divi’s Column Stacking Order on Mobile Devices (Elegant Themes)
👉 Related post: How to Change the Number of Columns in the Divi Blog Module (Elegant Themes)
👉 Related content: Complete FREE Divi course from VictorDuse.com
Hi there,
This article and the other article on change number of column (https://victorduse.com/blog/change-number-of-columns-on-mobile-in-divi/) is really useful. and robust. We can even set the gutter width to our liking on tablet and mobile. Thank you very much for the code.
But, what about the desktop itself? Of course we can use Divi row column feature there and adjust number of column according to our liking. But the one thing that really bother me is the inability to customize the gutter width between column on desktop. we stuck with 1-4 custom gutter width predefined by Divi. Do you have robust solution for this like the one you did for tablet and mobile? Would love to see solution for customizable gutter width on desktop. Thank you !
Hi Wan! That’s a really good idea. I’ll add it to my “to do” list. 🙂
there is a major css grid issue with setting it up like this
grid-template-columns: repeat(3, 1fr);
instead use
grid-template-columns: repeat(3, minmax(0, 1fr);
See
https://css-tricks.com/preventing-a-grid-blowout/
Thanks for sharing your thoughts. I wouldn’t say that the standard CSS Grid implementation is a “major issue” but sure, there are different solutions for different use cases.
the (your) outcome can result in NOT equal column widths
I see that you are posting several comments from the same IP address using different names. Don’t be a troll.
correct we work from the same office
it still does not change what we say
grid-template-columns: repeat(3, minmax(0, 1fr);
Lol, ”same office”, good one mate. Say hello to your little imaginary friend from me. Perhaps you two should start your own trolling blog?
Using this CSS and Code and your explanation is awesome and was exactly the solution I needed to resolve a 2 and 3 column layout mandatory for a website designed for portability.
Keep up the good work.
Cool, I’m glad to hear that Matthew! 🙂
code working fine divi builder, however no live result.
That’s probably a mobile browser cache issue. Have you tried incognito mode or with a different browser? Also, try to clear the site cache.
Awesome fix for Columns. My issue is with Divi on Phones. My content is presented from top to bottom instead of left to right. My site is http://www.largestincome.com/resources.
The videos are in a particular order where the site visitor will see them arranged from left to right. I want the videos to appear left to right (a1, a2, a3, b1, b2, b3, c1 etc. NOT 1a, 1b, 1c, 1d, 2a, 2b, 2c, 2d, 3a etc.) Is there a fix for this?
Any help you can provide is greatly appreciated. I’ll buy you a few beers and donate! Thanks
Hi Mike! I understand what you are looking for and here’s how I would do it:
1. Create one (1) row (instead of 4 rows) with just one (1) column (instead of three)
2. Give the row a unique class, for example duse-row
2. Place the videos in the order that you would want them to be displayed if they were to be distributed in three columns.
3. Apply CSS grid to display the videos in three columns on all viewports :
.duse-row .et_pb_cloumn {
display: grid;
gap: 20px; /* Adjust the gap to your liking */
grid-template-columns: repeat(3, 1fr);
Let me know how it goes! 🙂
Hi again! I just realized that I got lazy yesterday and missed the goal. This should work instead:
1. Create one (1) row (instead of 4 rows) with just one (1) column (instead of three)
2. Give the row a unique class, for example duse-row
3. Place the videos in the order that you would want them to be displayed on desktop if they were to be distributed in three columns.
4. Enable CSS grid in the column by adding this code:
.duse-row .et_pb_column {
display:grid;
}
5. Now let’s start by re-creating the 3 column design for desktop. Add this code:
@media all and (min-width: 981px) {
.duse-row .et_pb_column {
gap: 20px; /* Adjust the gap to your liking */
grid-template-columns: repeat(3, 1fr);
}
}
6. Now let’s change the order of the videos on tablet and phone devices. First add this:
@media all and (max-width: 980px) {
.duse-row .et_pb_column {
gap: 20px; /* Adjust the gap to your liking */
grid-template-columns: 1fr;
}
}
Now to the tricky party: You can rearrange the video modules on tablet and phone by using the CSS property order. By default, each element has the order:0. If you add the order:1 to an element, that element will be pushed down below the elements with a lower number. You can also use negative numbers like -3.
So you could use:
@media all and (max-width: 980px) {
.duse-row .et_pb_column:nth-of-type(2) {
order:4;
}
.duse-row .et_pb_column:nth-of-type(3) {
order:5;
}
}
To push down the video module 2 and 3 to lower positions, relative to the other video modules order numbers. You would need to give all video modules a custom order number, except for the first one that uses the default number 0.
With that said, if you don’t want to mess around with advanced CSS code, you could just create one section that is visible for desktop only and another section that is visible for mobile devices only, and arrange the columns using the Divi Builder. Here’s how you can display different content for different devices: https://www.elegantthemes.com/documentation/divi/visibility-options/