{"id":2441,"date":"2023-08-23T16:41:21","date_gmt":"2023-08-23T16:41:21","guid":{"rendered":"https:\/\/www.antpace.com\/blog\/?p=2441"},"modified":"2025-08-25T18:06:25","modified_gmt":"2025-08-25T18:06:25","slug":"css-grid-border-between-each-row","status":"publish","type":"post","link":"https:\/\/www.antpace.com\/blog\/css-grid-border-between-each-row\/","title":{"rendered":"CSS Grid: Border Between Each Row"},"content":{"rendered":"<h2>User Interface Layout with CSS<\/h2>\n<p>CSS Grid is a layout system that allows you to design web interfaces with rows and columns. In earlier times, developers used less elegant techniques to arrange UI elements. In the 1990s, using HTML <code>tables<\/code> was the standard way. Many of my earliest clients used tables for their entire website and email newsletter code bases. During that time Dreamweaver was a popular product that let designers build websites and generated source code that was mostly tables. The semantic problem what this approach was that we were using tables for non-tabular data.<\/p>\n<p>By the 2000s, the CSS <code>float<\/code> property became popular for multi-column layouts. We didn&#8217;t see Flexbox until the mid 2010s. You can read about examples of its use in <a href=\"https:\/\/www.antpace.com\/blog\/intersectionobserver-to-lazy-load-images-and-assets-on-wordpress\/\">the layout of my blog <\/a>\u00a0and an <a href=\"https:\/\/www.antpace.com\/blog\/easy-image-carousel\/\">image carousel<\/a> I built.<\/p>\n<h2>CSS Grid<\/h2>\n<p>Grid is the latest addition to the toolbox of options. For a recent project I used CSS Grid to create a two column web application. Here is some example HTML:<\/p>\n<pre>&lt;h1&gt;Below is a grid of data&lt;\/h1&gt;\n&lt;div style=\"display: grid; grid-template-columns:repeat(2, 1fr); grid-gap: 24px\"&gt;\n\t&lt;div&gt;Row 1, Column 1&lt;\/div&gt;\n\t&lt;div&gt;Row 1, Column 2&lt;\/div&gt;\n\n\t&lt;div&gt;Row 2, Column 1&lt;\/div&gt;\n\t&lt;div&gt;Row 2, Column 2&lt;\/div&gt;\n\n\t&lt;div&gt;Row 3, Column 1&lt;\/div&gt;\n\t&lt;div&gt;Row 3, Column 2&lt;\/div&gt;\n&lt;\/div&gt;\n<\/pre>\n<p>The grid container has a property: `grid-template-columns:repeat(2, 1fr);`. The CSS property <code>grid-template-columns<\/code> is used to define the number and size of columns in a CSS Grid layout. This <code>repeat()<\/code> function is used to repeat a pattern a specified number of times. In this case, the pattern is defined by the second argument, <code>1fr<\/code>. <code>fr<\/code> stands for &#8220;fractional unit.&#8221; <strong>This property is describing two columns, with each item taking up an equal amount of space.<\/strong> This is what it looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2445\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-23-at-12.10.41-PM.png\" alt=\"grid css layout\" width=\"1157\" height=\"479\" \/><\/p>\n<p>I wanted a horizontal line to separate each row. Usually, just adding a border-bottom to each of the grid items will work. In this scenario, the grid design called for a <code>grid-gap<\/code> property that forced the border to break.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2446\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-23-at-12.17.37-PM.png\" alt=\"css grid-gap\" width=\"1315\" height=\"301\" \/><\/p>\n<p>We fixed this by adding a new grid item between each &#8220;row&#8221; (that is, every third element). Those elements would represent each border line. I set the <code>grid-column<\/code> property of those elements to span two columns.<\/p>\n<pre>&lt;style&gt;\n\t.gridItemBorder{\n\t\tborder-bottom: 2px solid #333;\n\t\tgrid-column: span 2;\n\t}\n&lt;\/style&gt;\n\n\n&lt;h1&gt;Below is a grid of data&lt;\/h1&gt;\n&lt;div style=\"display: grid; grid-template-columns:repeat(2, 1fr); grid-gap: 24px\"&gt;\n\t&lt;div class=\"gridItem\"&gt;Row 1, Column 1&lt;\/div&gt;\n\t&lt;div class=\"gridItem\"&gt;Row 1, Column 2&lt;\/div&gt;\n\n\t&lt;div class=\"gridItemBorder\"&gt;&lt;\/div&gt;\n\n\t&lt;div class=\"gridItem\"&gt;Row 2, Column 1&lt;\/div&gt;\n\t&lt;div class=\"gridItem\"&gt;Row 2, Column 2&lt;\/div&gt;\n\n\t&lt;div class=\"gridItemBorder\"&gt;&lt;\/div&gt;\n\n\t&lt;div class=\"gridItem\"&gt;Row 3, Column 1&lt;\/div&gt;\n\t&lt;div class=\"gridItem\"&gt;Row 3, Column 2&lt;\/div&gt;\n&lt;\/div&gt;\n<\/pre>\n<p>The end result is just what we wanted:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2447\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2024\/01\/Screen-Shot-2024-01-23-at-12.26.12-PM.png\" alt=\"css grid layout with row separators \" width=\"1315\" height=\"391\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>User Interface Layout with CSS CSS Grid is a layout system that allows you to design web interfaces with rows and columns. In earlier times, developers used less elegant techniques to arrange UI elements. In the 1990s, using HTML tables was the standard way. Many of my earliest clients used tables for their entire website &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.antpace.com\/blog\/css-grid-border-between-each-row\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CSS Grid: Border Between Each Row&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3273,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[33,35,66,67],"class_list":["post-2441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-design","category-web-development","tag-css","tag-css-grid","tag-html","tag-html5"],"_links":{"self":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/2441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/comments?post=2441"}],"version-history":[{"count":1,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/2441\/revisions"}],"predecessor-version":[{"id":3274,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/2441\/revisions\/3274"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media\/3273"}],"wp:attachment":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media?parent=2441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/categories?post=2441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/tags?post=2441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}