Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

4 Simple Ways to Create CSS Product Grid

INTRODUCTION
THE POWER OF KNOWLEDGE

Welcome to a tutorial on how to create a simple CSS product grid. Once upon a time in the stone age of the Internet, we have to play with all sorts of same height CSS columns hack, and fight with digital dragons to get a proper grid. Thankfully today, CSS has become a lot more mature and much easier to create grids.

If you do a search on the Internet, you will find tons of product grid templates to choose from. But that is not what this guide is about. Instead of adding another “free templates download” post into the pile, this will teach you how to build one instead – Why struggle with the templates, when you know how to build one yourself? Read on!

I have included a zip file with all the source code at the end of this tutorial, so you don’t have to copy-paste everything… Or if you just want the CSS and skip the tutorial.

CONFESSION
AN HONEST DISCLOSURE

Quick, hide your wallets! I am an affiliate partner of Google, eBay, Adobe, Bluehost, Clickbank, and more. There are affiliate links and advertisements throughout this website. Whenever you buy things from the evil links that I recommend, I will make a commission. Nah. These are just things to keep the blog going, and allows me to give more good stuff to you guys - for free. So thank you if you decide to pick up my recommendations!

NAVIGATION
TABLE OF CONTENTS

Method 1
Floating Div

Method 2
Flexbox

Method 3
Grid

Method 4
Table

Extra
Download & More

Closing
What’s Next?

METHOD 1
FLOATING DIV

Let us start with one of the more traditional ways of doing product grids – By using floating divs. Although I will recommend using the more modern flexbox and grid, this one is still an old reliable that is good to know.

THE BASICS OF FLOATING DIV

1a-basics.html


  
    Floating Div Basics
Product
Product
Product
Product
Product
Product

The magic that drives the floating method is a 

 container full of 
. Yep, we set all the child 
 within the container to float:left, give them a percentage width, and that is pretty much the mechanism behind it.

But please do take note that unlike tables, the “cells” in this method will not be of equal height – If one cell is taller than the other, it may cause the entire layout to break. There are 3 usual “fix” that we apply:

  • Limit the height of each cell.
  • Meticulously limit the size of the product image, the number of characters for the product name, price, description – So that they will be of equal height.
  • Set the container to display as a table, the children as table cells.

THE PRETTY VERSION

1b-float.html


  
    Floating Div Product Grid Demo
Item A
$99.99
Lorem Ipsum Dolor Sit amet, consectetur adipiscing elit.
Item B
$88.88
Lorem ipsum Dolor Sit Amet, consectetur adipiscing elit.
Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Pretty much the same mechanics as above, but complete with demo products, bells, and whistles.

THE RESULT

Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

METHOD 2
FLEXBOX

This next method is a true savior to the web developers. Equal height columns and grid arrangements used to be a nightmare, and the flexbox made it so easy.

FLEXBOX BASICS

2a-basics.html


  
    Flexbox Basics
Product
Product
Product
Product
Product
Product

The flexbox is still a 

 container with 
cells, except that we no longer have to do all the float and crazy calculations.
  • First, we set the container to display:flex.
  • flex-direction: row will automatically layout the children in the horizontal orientation.
  • flex-wrap: wrap will break into a new row when the cells span out of the container width.
  • Finally, we only have to define the width of the cells.

THE PRETTY VERSION

2b-flex.html


  
    Flexbox Product Grid Demo
Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

THE RESULT

Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

METHOD 3
GRID

The CSS grid is a cousin of the flexbox, and pretty much another piece of cake.

GRID BASICS

3a-basics.html


  
    Grid Basics
Product
Product
Product
Product
Product
Product

The CSS grid layout works somewhat the same as flexbox.

  • We set the container to display: grid.
  • Then, we use grid-template-columns to define the width of the cells.
  • That’s it. The browser will take care of the rest.

THE PRETTY VERSION

3b-grid.html


  
    Product Grid Example
Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

THE RESULT

Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

METHOD 4
TABLE

Tables are one of the oldest ways to create a product grid, but I will not recommend using this – As easy as this may be, it is not responsive, and I am leaving this here only as an “honorable mention”.

TABLE GRID BASICS

4a-basics.html


  
    Table Grid Basics
Product Product Product
Product Product Product

I guess this one needs no explanation – The table grid is what it is… We are practically just displaying the products in an HTML table.

THE PRETTY VERSION

4b-table.html


  Table Product Grid DemoFloating Div Basics
Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

THE RESULT

Item A
$99.99
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item B
$88.88
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item C
$77.77
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item D
$11.11
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item E
$22.22
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Item F
$33.33
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

EXTRA
DOWNLOAD & MORE

That’s all for the code, and here is the download link as promised – Plus a small extra that may be useful to you.

WHICH IS THE BEST?

I will personally recommend using the grid and flexbox, which is supported on most modern browsers these days. But if you have to deal with ancient browsers, then consider the floating div… Just avoid using tables, as that is an outdated way to do product grids.

DOWNLOAD

Click here to download the source code in a zip file – I have released it under the MIT License, so feel free to build on top of it if you want to.

CLOSING
WHAT NEXT?

Thank you for reading, and we have come to the end of this tutorial. I hope it has helped you to make a better eCommerce website, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!


The post 4 Simple Ways to Create CSS Product Grid appeared first on Code Boxx.



This post first appeared on Xxxxxxxxx, please read the originial post: here

Share the post

4 Simple Ways to Create CSS Product Grid

×

Subscribe to Xxxxxxxxx

Get updates delivered right to your inbox!

Thank you for your subscription

×