
CSS Grid is a powerful tool for creating complex layouts, and one of its key features is the ability to add borders between rows and columns.
By using the `grid-row-gap` and `grid-column-gap` properties, you can add space between rows and columns. For example, setting `grid-row-gap: 10px` will add a 10px gap between rows.
Adding borders between rows and columns is a great way to create a clear and organized layout. In a grid container with three rows and three columns, you can set `grid-row-gap: 5px` and `grid-column-gap: 10px` to create a balanced and visually appealing design.
The gap between rows and columns can be adjusted to suit the needs of your design.
If this caught your attention, see: Css Grid Width
CSS Grid Basics
CSS Grid Basics are the building blocks of creating responsive and flexible layouts.
Grid containers are the starting point for creating a grid, and they can be defined using the grid-template-columns and grid-template-rows properties.
A grid container can have multiple rows and columns, but we'll be focusing on a simple 2x2 grid layout.
See what others are reading: Css Grid Template Column
Grid items are the content elements that are placed inside the grid container, and they can be defined using the grid-column and grid-row properties.
Grid items can span multiple rows or columns by specifying the grid-column and grid-row properties.
In our example, we have a grid item that spans two columns and two rows, taking up the entire grid container.
Explore further: Css Grid Align Items
Setting Up Grid Rows
To set up grid rows with borders, you'll need to define the height of each row, which is done using the --line-thickness token with a value of 2px.
The height is set using the --line-thickness token, and the position of the border is controlled using the inset-inline-start and inset-block-start properties.
The --line-offset value is used to position the border, and since it needs to be a negative number, you can simply multiply any value by -1 to achieve this using the calc() function.
Readers also liked: Css Grid Row Height
User Interface Layout
CSS Grid is a layout system that allows you to design web interfaces with rows and columns.
In the 1990s, using HTML tables was the standard way to arrange UI elements, with many websites and email newsletters built entirely with tables.
Dreamweaver, a popular product at the time, let designers build websites and generated source code that was mostly tables.
The semantic problem with this approach was using tables for non-tabular data.
The CSS float property became popular for multi-column layouts in the 2000s.
Flexbox didn't emerge until the mid 2010s, with examples of its use found in the layout of the author's blog and an image carousel built.
Step 5: Row Lines
Setting up grid rows can be a bit tricky, but don't worry, I've got you covered.
To set a height for our grid rows, we need to use the --line-thickness token, which has a value of 2px. This will give us a consistent height for our row lines.
We'll also want to set the left (inset-inline-start) position to 0 and the top (inset-block-start) position to our --line-offset. But here's the thing: we need our offset to be a negative number to move it away from the grid item and into the gap space. That's where the calc() function comes in handy - we can simply multiply any value by -1 to make it negative.
Expand your knowledge: Css Grid Auto Rows

The reason we don't see a border on top of the grid is because of the overflow hidden we set earlier. This means that the pseudo-elements are offset, making them appear outside of the grid, which is a hidden area.
Here's a quick rundown of the properties we've used so far:
By using these properties, we can create a "border" within every row of our grid, which is a pretty cool effect.
Goals and Requirements
We need to set up grid rows in a way that meets certain requirements. One key goal is to have the freedom to change the number of grid columns without breaking the borders.
To achieve this, we need to account for a few things. We must ensure that a grid with a missing grid item doesn't break the borders.
Here are the key requirements to keep in mind:
- We need to avoid changing our instructions at various breakpoints.
- We should avoid using crazy :nth() selector tactics that limit our flexibility to change column counts.
This will help us set up grid rows that degrade gracefully from breakpoint to breakpoint, ensuring a smooth user experience.
Customizing Grid Appearance
You can change the number of grid columns without affecting the borders by using a CSS grid layout with a grid gap set to 0px.
To achieve this, we need to be able to change the number of grid columns without affecting the borders, a grid with a missing grid item should not break the borders, the borders should degrade gracefully from breakpoint to breakpoint, and we want to avoid crazy :nth() selector tactics.
The key is to use the ::after pseudo-element for row line and ::before pseudo-element for column line.
A width of 100% for the row line would make it only the width of each grid item, causing issues with uneven items in the grid.
To span the entire width of the grid container, use a width of 100vw, which is designed to span the entire width of the viewport.
For the column line, use a height of 100vh to create a line from top to bottom of the grid item on the left side.
You might like: Css Grid Row Span
To move the column line to the top of the grid item, use the left -1px property.
Here's a summary of the properties you can use to customize your grid appearance:
By using these properties, you can create a clean and customized grid layout with border lines between rows.
Featured Images: pexels.com


