Columns: width classes for better responsive design

Hi guys,

I’ve got a suggestion, but with a solution already :wink: So I thought I’d share it here with you.

The problem:

Currently, there is not very intuitive way of controlling how the columns would be stacked on smaller screens, as far as I know. Take 4 columned row, for example. Once the screen is narrower it simply stacks from 4 columns layout (4 col in 1 row) into 1 column layout (1 col in 4 “rows”). I’d like to see something in between for better responsiveness. Something like 4 columns layout on desktops, 2 columns (2 cols in 2 “rows”) on tablets and 1 column layout on mobiles.

The solution:

Add additional width classes on columns to provide better targeting via CSS.

Solution via custom code in your theme:

Please note this is only PHP solution for adding the classe, I don’t provide responsive CSS here.

Put this PHP for adding additional column classes into your theme’s functions.php file, for example.

Please note that I am not fan of the one-third, one-half and similar classes, so I add column width classes in this format: fl-col-width-2-3 should be read as column with width of 2/3, so the two-thirds width class equivalent. If the width is some custom one, there is fallback class applied - the fl-col-width-custom.

function my_beaver_builder_column_class( $class, $col ) {

  // Column width class

    switch ( $col->settings->size ) {

      case '100':
        $class .= ' fl-col-width-1-1';
      break;

      case '50':
        $class .= ' fl-col-width-1-2';
      break;

      case '33.33':
      case '33.34':
        $class .= ' fl-col-width-1-3';
      break;

      case '66.66':
        $class .= ' fl-col-width-2-3';
      break;

      case '25':
        $class .= ' fl-col-width-1-4';
      break;

      case '75':
        $class .= ' fl-col-width-3-4';
      break;

      case '20':
        $class .= ' fl-col-width-1-5';
      break;

      case '16.65':
      case '16.66':
        $class .= ' fl-col-width-1-6';
      break;

      default:
        $class .= ' fl-col-width-custom';
      break;

    }

  // Output

    return $class;

} // /my_beaver_builder_column_class

add_filter( 'fl_builder_column_custom_class', 'my_beaver_builder_column_class', 10, 2 );

Hope this will help somebody or you guys might consider adding similar width classes into a plugin future version sometimes.

I post it here in support forum 'cause it is not really a suggestion as I provide a solution already :wink:

Thanks and regards,

Oliver

Hey Oliver,

Thanks for sharing. This is indeed a great solution for better class targeting. :slight_smile:

Ben

Great solution, Oliver. With Genesis and Dynamik Website Builder (as underlying foundation for Beaver Builder) you can even do this without writing code. Dynamik has interesting techniques for the different breakpoints and resulting stacking orders. Basically you are completely free to style as you want.

Regards, Leo

Hey Leo, could you elaborate on how you would do the breakpoints in Dynamik? I’m still stumbling through css and php and I couldn’t figure out how to implement Oliver’s code, but I am using Dynamik so maybe your solution would help me. You don’t use any of the EZ widget areas in Dynamik with BB, do you?

Thanks for your help!
Fran