Search code examples
cssgridcss-gridheight

How to obtain a grid of equal height list items?


I am trying to do a grid of products using list items and inline-block. The problem is that the content of the blocks has various heights and the inline-block doesn't keep the heights equal.

The code:

#blocks ul{
  list-style-type:none;
  margin:0px;
  padding:0px;
}

#blocks li {
  display:inline-block;
  vertical-align:top;
  width:280px;
  background-color:#ff9933;
  padding:13px;
  margin: 0px 0px 20px 19px;
}

<div id="blocks">
    <ul>
       <li>...</li>
       <li>...</li>
       <li>...</li>
    </ul>
</div>

Here's an image to illustrate the issue.

I need the blocks to keep the same height as the larger blocks, independently of their content. Is it possible to make something like this:

this?


Solution

  • 1. Adding the following to the li CSS will mimic the image example you provided.

        height: 150px;
        min-height: 150px;
        overflow:auto;
    

    2. Also, here are some other approaches: