Easy Card Layout with Bootstrap

Many content-rich websites are using card layouts to provide a quick view of the site content. An example of this is the layout of Pinterest.


Bootstrap

Bootstrap provides great CSS and JavaScript libraries that make responsive web design quick and simple. In order to use the JavaScript portion of Bootstrap, you will also need to include JQuery. You can include these directly from the source in the head section of your page without needing to download anything.



Include the following code in the head section of your HTML page:


Bootstrap Grid System

Bootstrap treats a page as a grid of 12 columns. You can specify the size of a div for 3 different screen sizes by using sm (small), md (medium), lg (large). The sum of all columns in a row needs to add up to 12.
For more information about this, visit the W3 School Bootstrap Grid tutorial.

Replicating the Pinterest Layout

In replicating the Pinterest Layout, we will use a total of 6 columns for a medium screen. Since Bootstrap needs a sum total of 12, we will set a size of 2 for each column because 2 * 6 columns = 12.

The following code has a row, and 6 columns on a medium screen:

Style the content

The typical use of the card layout has a shadow around each card. The box-shadow CSS property allows us to easily add this feature. In the typical card layout shown on Pinterest, the cards are of varying sizes and extend down each column. Within each column, we will create a new row with a column that spans 100% of the space. This will be our actual card where we will add the shadow.

The following code is placed in between each column div (The content will need to be changed to display different information in each card): The following code is used to style the CSS: The Bootstrap row class was overwritten to set the margins of the row to 0. This prevents the row from spanning all the way to the edge of the website.

Putting it all together:

Add multiple cards with the sub-box class to expand the cards down your columns. The following is a link to the sample page that I created for this tutorial.
View Sample Page

Comments