I don’t know about you, but for me, mobile responsiveness is important. Like, really important.
At work, I spend hours working on how every single page looks like on up to 7 screen sizes, 5 different devices, with 3-4 browsers per device.
(I’m not kidding. It’s a LOT of work, but I’m happy that the websites I build look great anywhere, everywhere.)
Plus we work on making every margin, padding, leading, tracking, and font-size look its best on any given device.
However, the mobile responsiveness of Divi is very underwhelming.
It doesn’t have many breakpoints, nor does it allow you to control how they respond.
Does any other theme/builder allow you to do so?
Well, some do partially, but there’s no ONE builder or theme that does everything properly.
So we might as well just code things ourselves. 🙂
Notice
If you want to learn how to edit Divi and build with awesome responsiveness in mind, check out the course I made.
Back to the post… So, flexbox to the rescue.
Here’s an example of how you can use flex to control responsive behavior.
Let’s start with some full-width multi-column image banners.
Here’s a simple layout. (It’s a bit bandy, but this is just for demonstrative purposes, so please excuse the bandiness. haha. Oh, and I’ve offered to redo my daughter’s gym’s website, so I have some stock photos of gymnasts, dancers, and ballet..ers..? ballers? no.. ballet dancers..?.. anyways, that’s why I’m using those photos..)
Looks nice. However, the problem arises when we get to mobile.
I know y’all know how things stack, but yeah, here, have a look..
I think there are some problems with this kind of stacking.
a. The original layout was made in a way for the 4 images to be just a horizontal strip, and the image below that section is supposed to be more prominent. However, in mobile, the 4 images are WAY more prominent. Not ideal.
b. Too much scrolling for images that are not important enough to fill the whole screen and more.
I think that’s a problem.
So, let’s find a way to fix this.
First, let’s make the images clickable into lightbox. So even when the images are smaller on the phone, people can click it to zoom in.
Next, let’s add some classes to the sections.
Start with flex-columns
Let’s do this to all the sections that will have images all the way across with 2, 3 columns.
However with a 4 column section..
Let’s add something extra:
So, why did I do that? I think 2 or 3 images side by side on mobile is okay, but 4 is a bit too much. It’s a bit too small per picture, so I think they should be a grid of 2 X 2. So I added another class to make that section different.
And here’s what we get!!
2 columns
3 columns
4 columns
Of course, you need to add the css, that’s right here!
@media (max-width: 980px) { .flex-columns .et_pb_row { display: flex; } .flex-columns.twobytwo .et_pb_row { display: flex; } .flex-columns.twobytwo .et_pb_row { flex-wrap: wrap; } .flex-columns.twobytwo .et_pb_row .et_pb_column { width: 50%; } } @media (max-width: 479px) { .flex-columns.twobytwo .et_pb_row { flex-wrap: wrap; } .flex-columns.twobytwo .et_pb_row .et_pb_column { width: 50%; } }
(update: somewhere around mid 3.20’s version of Divi, ET lowered and changed the CSS specificity, so I took out the !importants. If you’re on an earlier version, and the default CSS is overriding this CSS, then add the !importants back in after the ‘50%’ parts.)
[sc name=”customcss”]
I’ll break it down for you:
1. Flex is added
2. The columns stay together. (This means you can use this for other types of modules, not just images!)
3. They won’t go all HUGE FULL SCREEN WOAH WHAT’S GOING ON on iPad portrait. (I dislike the monstrous stacking on iPads, portrait is still a great size to consider it paper-like, meaning, horizontal layouts are totally fine.)
4. The four column section gets flex-wrap applied.
5. The columns inside the wrap gets 50% width, so they’ll stay together in a 2X2 grid.
(Best part is) you can use this for other types of modules too!
I don’t have a demo layout for you to check, you can watch the video, to see it in action.
Hope this helps, if you have any questions, let me know in the comments below!
[sc name=”learn css”]
[sc name=”responsive-ad”]
[sc name=”podcast”]
PS. I have thought about sharing the layout (for free), and if you’re interested, let me know, and I’ll try to hurry and package it and upload it. Oh, and how about signing up for the newsletter to stay updated? Thanks!
Edit: cleaned up the CSS a bit to make it easier to read.
Anonymous says:
5
Hadee roslan says:
Thank you for sharing this. Will test it out and put it to good use in my sites.
😀 😀 😀
ProStrona says:
Great tutorial. I will definitely use the code provided. Thank you!
JUl says:
Just worked perfectly 🙂 Thank you so much for this tutorial and for helping me out with my last questions !!
Made my day 🙂
All the best to you PK !!
Alejandro Sepulveda says:
It isn’t working for me 🙁 I have put the CSS on the Divi CSS editor and used the CSS class on the column that I want to prevent from staking on mobile but something is happening that is not working for the moment in the mobile is still stacking,
It is on the second column that i want to prevent on mobile from stacking
Leanne says:
Thank you so much, this worked for me brilliantly.
Leni Neto says:
Really nice tip! Super easy to easy and customize.
Thanks!
Dirk Hofman says:
Wow, this looks really great on mobile and with a minimum css! Thanks for that. May be you can let us/me know how to add some space between the two columns?
Megan says:
Hi there! Thank you so much for this tutorial, it has worked great with a section with three images on my site! hHowever I would now like a section with four images to flex into one line (as opposed to a 2x2grid) – even though this makes the images very small, they’re just icons and i would ideally like a row of four icons side by side on mobile screens. Ive tried the flex-columns css class on this section but its not doing anything. I’m probably being super dim! Could you help me out? Thank youuuuu 🙂
Tamsin says:
Hi iPK
This is legendary and helped with my website layout which was looking awful in a tablet….so I got everything to display two by two, not stacked in one long collumn as per Divi, but I am really coming unstuck with mobile portrait mode…where I can’t seem to force the one collumn only, it still shows 2 by 2 but goes off the screen.
If you have a moment could you point me in the right direction…however I am going to continue to research more about the flex property and try to figure this out on my own.
Here is a link to the page where I am struggling to get the top buttons to display on portrait mobile:
https://zencapetown.co.za/make-a-booking/
Appreciated in advance
Tamsin
Luke B says:
Hi, thanks for an awesome tutorial. I tested it out on one of my websites and the 2 column works great on mobile, but three does not. I then looked at the CSS and see mentions of 50% but there’s no mention of 33% so I’m wondering if you missed out a bit of code? I’m just being lazy, rather than doing it myself 😉 Maybe I missed something?
Tina Stenger says:
Wow PK, your generosity is really astounding and I am so grateful. Thank you so much for the time in creating and sharing all these perfect tutorials, and ad-free as well. I’m going to study up and maybe I can finally understand flex!
Shyam Reyes says:
Worked perfectly for the website makeover I’m working on. Thanks!
Orana says:
This worked perfectly for some blurbs that kept stacking and looking terrible on mobile!
I needed to tweak some sizes for it to look perfect but all in all the css worked great.
Thanks!
Florian says:
Thanks for this! Works perfect! Can you tell me, how I can add a padding between the banners on mobile?
All the best, Florian
Fee Lanzino says:
Hi there – this worked perfectly when in mobile (4 columns stacked 2by2) – so thank you for that – perfect. The only issue I have now is that it doesn’t work in tablet view and has gone into one long line! please help! (the icons on our home page) THANKS 🙂
michael shatravka says:
What a success thank you so much!
David says:
Hi PK. The problem I have is that I have 4 modules in a row and on mobile they stack as 2×2.
How can I force each module onto a line of it’s own?
Jordana says:
Hi! Thank you for this tutorial. I’m new to the custom CSS and I’m not seeing any changes when I input the custom CSS. I’m putting it under main element in the section settings is that correct? Thank you!
James says:
Hi PK
Thanks for sharing the info. I am struggling to get this to work in Extra theme. I am also new to css.
Any advice will be appreciated.
Thanks
ADAM says:
Great info! But how do I prevent stacking for desktop/laptop view? I would like to override the default breakpoints for desktop/laptop browsers. To be more specific, I like the layout of my site when viewed full screen. But when I shrink the browser window to be more narrow, there’s a certain point when any modules that are normally next to each other stack on top of each other. And I hate it! I want the modules to stay next to each other on desktop/laptop view. Does that make sense? Will your steps above apply in that situation?
MIchelle says:
Hi. I have used this code on a couple of sites and it has worked great – thanks! However, on the latest site, it has worked to stack 4 blurbs in a neat side by side box in mobile, but not tablet. What could I be missing?
Emily says:
Hi PK,
Thank you so much for this great article. I have achieved the layout that you’ve outlined. I’m hoping you can help me though because I can’t find information on how to extend on this. My question is if I have a section that I have spilt the row: 2/3 x 1/3 (66% x 33%), how can I get this same effect instead of 50% x 50%? Thank you for any tips!
Emily
Emily says:
Hi PK,
A complete success. Thanks so much again! 😀
Isa says:
Awesome! This worked perfectly. Thank you so much!
Raul says:
Thanks PK! this has helped immensely when optimizing our sites for mobiles and solved a lot of spatial issues we had previously.
brianna strobel says:
Hi! This has worked great for so many areas of my site, thank you! Can you acheive a similar effect by adding custom classes to the row directly? I have rows within a specialty section’s column that I want this effect in. When I add it to the speciality section, it messes up all of the other parts.
forest Cavemann says:
Hi there! Can you tell me where to add the CSS? Inside the section of Divi visual builder or where? Thanks!
jen says:
I love this code and the functionality, but I’m having an issue due to the sections I’m having to use being 5 columns. Putting them into two side by side works for the first 4, but that 5th column just has blank space next to it instead of the first item in the next section. Any advice on how I can force it to push the next item into that space.? Otherwise, I have a page full of:
item item
item item
item
item item
item item
item
…and so on.
(Unfortunately, I have to keep the items in separate sections for reasons too long for a comment, otherwise I know having them all in one section would be ideal.)
Marina says:
Hello PK,
for some reason I couldn’t reply to your comment. I changed the icons and the button, now they are smaller. I would be fine with them sitting 2-2-1 on mobile. Thanks for your help.
Mandy says:
Hey PK,
Thanks for your generosity with your time!
I’ve got your code working all great.
The only problem I have is that even without adding “twobytwo” to the css class for sections with 4+ columns, they still show up 2 in a row in tablet or mobile view.
There are a few instances where I would like the option to have 4 or more items stay next to each other in a section.
It seems as though Divi automatically converts rows with 4+ columns to stack:
item, item
item, item
So that may be overriding what I’d like to do in keeping them next to each other.
Any ideas?