Gary Sieling

Building responsive grids with React Bootstrap

React Bootstrap is a nice wrapper around Bootstrap, allowing you to build screens with Bootstrap components, hiding a little bit of the need for knowledge of Bootstrap’s CSS.

To render a table, React Bootstrap provides React classes named “Grid”, “Col”, and “Row”, which can be used interchangeably in a table.

For instance, to render a responsive faceted search display for FindLectures.com, I’ve written markup like this:


  
    
            
  
    
{countDescription}
{facets} {searchResults}

The important part of this are the parameters: xs, sm, md, and lg. The Bootstrap grid system is a 12 column grid, and these tell Bootstrap how many column units each component should consume, depending on the screen size. The smallest size, xs, is for phones, all the way up to large displays. You can also tell Bootstrap to swap an object to the right/left by a certain number of columns, using props like lgPush/lgPull, move to the right with lgOffset, and hide columns at a certain display size with lgHidden.

To test this, you can simply resize your browser, to see the different rendering sizes.

By default, each column is a percentage of the total screen size – for certain scenarios this can become unrealistic. For instance, I found that for facets I don’t want the facet panel to become wider than the widest facet, which is why I manually set max-width in the above example.

Exit mobile version