Setting the Divi Theme Sidebar Background Color

Written by Dan Mossop

The Divi Theme has a flexible sidebar which can be positioned on either the left or right of the page (or hidden altogether). Unfortunately, the way that the sidebar is structured actually makes it very difficult to set the background color with margins, etc, that actually look good. Here, then, is how to change its background color by adding some CSS to the theme.

Updated: I've recently revisited this and come up with a new method which works much more cleanly with Divi's natural flow. It can also be applied with out affecting the existing layout at all. I've included both methods here.

Method 1: The Old Way

We can start by setting our desired background color on the "sidebar" element, like so: 

#sidebar { background-color: #fafafa; }
For a light-grey background. Or for a semi-opaque black background:
#sidebar { background-color: rgba(0,0,0,0.5); }

You'll notice however, if you do this, that it doesn't look particularly good. The sidebar element tightly surrounds the content meaning that the contents of the sidebar are right up against the edge of the sidebar.

To fix this we can adjust the padding and margins. We need to specify several sets of padding and margins to handle the various screen sizes supported by Divi. Here is an example set of padding and margin rules which I think gives a nicer result:

@media only screen and (min-width: 1100px) { /* full-size screens */
    .et_left_sidebar #sidebar {  /*left*/
        padding:70px 0 200px 30px; 
        margin:-70px 0 0 -30px;
    }
    .et_right_sidebar #sidebar { /*right*/
        padding:70px 30px 200px 0px; 
        margin:-70px -30px 0 0;
    } 
}
@media only screen and (min-width: 981px) { /* medium-size displays */
    #sidebar { 
        padding:70px 30px 200px 30px; 
        margin:-70px -30px 0 -30px; 
    }
}
@media only screen and (max-width: 981px) { /* mobiles, etc */
    #sidebar { 
        padding:30px 
    }
}

 This code works for both left and right sidebars.

 

Method 2: The New, Better (But Longer) Way

Here's my preferred method of setting the Divi Theme's background color as it provides a much neater and more natural integration with Divi.

#sidebar { background-color: #fafafa; }

/* Increase the container width by 60px to provide space for outer margins */
@media only screen and (min-width: 1100px) {
    .et_right_sidebar #main-content .container,
    .et_left_sidebar #main-content .container {
        width:1140px;
    }
}
@media only screen and (min-width: 981px) and (max-width:1099px) {
    .et_right_sidebar #main-content .container,
    .et_left_sidebar #main-content .container {
        width:1020px;
    }
}

/* Add outer padding */
@media only screen and (min-width: 981px) {

    /* Add 30px margin to outside edge of sidebar */
    .et_right_sidebar #sidebar .et_pb_widget { margin-right:30px }
    .et_left_sidebar #sidebar .et_pb_widget { margin-left:30px }

    /* Add 30px margin to outside edge of main area (for balance) */
    .et_right_sidebar #left-area { margin-left:30px }
    .et_left_sidebar #left-area { margin-right:30px }
}

/* Declare the sidebar width */
@media only screen and ( min-width: 1100px ) {
    .et_left_sidebar #sidebar,
    .et_right_sidebar #sidebar {
        width:254px;
    }
}
@media only screen and (min-width: 981px) and (max-width:1099px) {
    .et_left_sidebar #sidebar,
    .et_right_sidebar #sidebar {
        width:224px;
    }
}

/* Fix the inside padding / margin on medium screens */
@media only screen and (min-width: 981px) and (max-width:1099px) {
    /* Reduce inside margin on main content */
    .et_right_sidebar #left-area {
        margin-right:30px
    }
    .et_left_sidebar #left-area {
        margin-left:30px
    }

    /* Add as inside padding to sidebar instead */
    .et_right_sidebar #sidebar {
        padding-left:30px
    }
    .et_left_sidebar #sidebar {
        padding-right:30px
    }
}

/* Fix the dividing line position */
@media only screen and (min-width: 981px) {

    .et_right_sidebar #main-content .container:before {
        right:254px;
    }
    .et_left_sidebar #main-content .container:before {
        left:254px;
    }
}

/* Extend sidebar vertically */
@media only screen and (min-width: 981px) {
    .et_right_sidebar #sidebar,
    .et_left_sidebar #sidebar {
        margin-top:-100px;
        padding-top:100px;
        padding-bottom:10px;
    }
}

/* Add padding on small screens (mobiles, etc) */
@media only screen and (max-width: 981px) {
    #sidebar { padding:30px !important;margin:0 0 30px 0 !important; }
}

Again it works on both left and right sidebars.

Another thing you may consider doing to enhance the look of the sidebar is removing the dividing line.

We may earn a commission when you visit links on our website.

Unlock the Full Potential of Shortcodes in Divi!

Empower your Divi site with the Divi Shortcode Enabler. This plugin allows shortcodes to run effortlessly in various Divi module fields, enhancing functionality and customization across your site.

Latest Posts

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Random Posts

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. Hi Dan,

    Where would I add the code in method 2? I have followed your tutorial on copying code into Divi them but can't seem to see any changes. I am using a child theme and have tried placing the css code in different parts and nothing seems to change the sidebar.

    Hope you are able to assist.

    Reply
    • Hi Mike, the CSS can be added either into the Custom CSS box found at "Divi > Theme Options > General > Custom CSS", or into the "style.css" file within your child theme. Assuming neither of these is working, are you able to send me a link to the site you are working on so that I can take a look at what's going wrong? Thanks!

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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