Vertically Align Modules Inside Rows, and Rows Inside Sections

by Feb 10, 2018Alignment Hacks4 comments

When you want the Divi section’s content (rows and modules) to be horizontally AND vertically centered within the section, there’s a nice little CSS snippet that gives our sections this absolute centered look. This works really well if you are setting specific heights for sections and rows that relate to the height of the browser window (example: min-height:80vh, or height:100vh).

For those of you who don’t know what vh is, vh is short for viewport height, which is the height of the browser window on whichever device you are on. There’s also vw – viewport width – which is the width of the browser window.  The number before vh or vw represents 1/100th of the vh or vw, so basically 1%. Therefore, 80vw equals 80% of the viewport width, and 100vh equals 100% of the viewport height (covering the full window).

Use the following code to center the content in your rows and sections.

   Paste the following CSS to your Custom CSS box

/****** Vertically center rows in sections and modules in columns *******/  
.dh-valign-center-row .et_pb_column,
.dh-valign-center-section,
.dh-valign-center-module {
   display: flex;
   flex-direction: column;
   justify-content: center;
}

Vertically and horizontally center a row within a section.

A   Add dh-valign-center-section to the section’s CSS classes box.

Vertically and horizontally center a module within the row’s column(s).

B   Add dh-valign-center-row to the row’s CSS classes box.

   Turn on equalize column heights.

Vertically and horizontally center the content within a module.

C   Add dh-valign-center-module to the module’s CSS classes box.

Done!

Give this page a share, like, or comment if this worked for you! Leave a comment if you have a question or want to share some love 😀

4 Comments

  1. Pascal

    Excellent ! It worked fine for me, very usefull !
    On the other hand I don’t understand why this is not a standard feature in such a popular tool as WordPress and why we have to loose time finding such workaround.

    Reply
  2. Dave

    Thank you for this snippet! It helps me very much!
    But how i can do this if i have two stacked rows and i want to keep this stack centered in section?

    Hope you understand, my english is not perfect.

    Reply
  3. Boz

    Thanks for the tip ;)

    Reply

Submit a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.