Change Number of Columns in Divi Portfolio Module

Jun 15, 2020 | Blog, Divi Tutorial | 2 comments

In this article I will share the CSS Code and the steps to change the number of columns in a Portfolio module in the Divi theme.

The code can used to change the column number when the Portfolio module is set to use the Grid layout. The codes shared below will work on both the Filterable Portfolio module and the Portfolio module.

1. Add CSS Class To The Divi Portfolio Module

The first thing that you need to is add a CSS Class the Portfolio module. We normally add a class in the module so that we only apply the code to a specific module on the website and not affect any other modules on the website.

The CSS Class can be added at Portfolio Module Settings > Advanced > CSS ID & Classes > CSS Class. For this tutorial we are going to add the class lwp-col-portfolio to the portfolio module settings.

If you are not sure here is a screenshot to help you understand where to add the CSS Class.

Divi portfolio module css class to change number of columns

2. Add CSS Code to Change The Number of Columns

After adding the CSS Class to the Portfolio module you need to add the following CSS Code in the Theme Options of your website.

Please go to your WordPress Dashboard > Theme Options > General > Custom CSS and add the code below. This code will change the number of columns in the Portfolio module from 4 columns to 3 columns.

@media (min-width: 981px) {
    .lwp-col-portfolio .et_pb_grid_item {
        width: 29.66%!important;
        margin-right: 5.5%!important;  
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(3n) {
        margin-right: 0!important;
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(4n) {
        margin-right: 5.5%!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.et_pb_portfolio_item:nth-child(4n+1) {
        clear: none!important;
    }
    .lwp-col-portfolio .et_pb_grid_item.first_in_row {
        clear: unset;
    }
}

If you are not sure where to add the code then here is a screenshot to help you.

Divi Custom CSS Theme Options

If you want to change the number of columns in the Portfolio module to 2 columns, 5 columns or 6 columns then you can use the codes that are listed below.

Code to Change The Number of Columns To 2

@media (min-width: 981px) {
    .lwp-col-portfolio .et_pb_grid_item {
        width: 47.25%!important;
        margin-right: 5.5%!important;  
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(3n) {
        margin-right: 5.5%!important;
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(2n) {
        margin-right: 0!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.et_pb_portfolio_item:nth-child(4n+1) {
        clear: none!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.first_in_row {
        clear: unset;
    }
}

Code to Change The Number of Columns To 5

@media (min-width: 981px) {
    .lwp-col-portfolio .et_pb_grid_item {
        width: 15.6%!important;
        margin-right: 5.5%!important;        
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(3n) {
        margin-right: 5.5%!important;
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(5n) {
        margin-right: 0!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.et_pb_portfolio_item:nth-child(4n+1) {
        clear: none!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.first_in_row {
        clear: unset;
    }
}

Code to Change The Number of Columns To 6

@media (min-width: 981px) {
    .lwp-col-portfolio .et_pb_grid_item {
        width:12.0833%!important;
        margin-right: 5.5%!important;        
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(3n) {
        margin-right: 5.5%!important;
    }

    .lwp-col-portfolio .et_pb_grid_item:nth-child(6n) {
        margin-right: 0!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.et_pb_portfolio_item:nth-child(4n+1) {
        clear: none!important;
    }

    .lwp-col-portfolio .et_pb_grid_item.first_in_row {
        clear: unset;
    }
}

Next you can checkout some other Divi tutorials from our Blog such as How to Autoplay Videos in the Divi Video Module or How to add Labels above Input Fields in the Contact Form Module.

Leave a comment below if you found this helpful or have any questions. Don’t forget to subscribe to the Newsletter to receive the latest tutorials in your inbox.

2 Comments

  1. Martin

    Hello I used your method, but in the site I am setting looks ugly. Can I use this method with fullwidth portfolio?

    Reply
    • LearnHowWP

      This code cannot be used for the Fullwidth Portfolio module. It will only work for the default portfolio modules. I will look in to it later and write another blog post for it if possible.

      Reply

Submit a Comment

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

Affordable Web Hosting With Great Customer Service

Starting At Just $1.44/Month