How To Set Gap In CSS Grid

February 24, 2023

CSS Grid is a highly flexible layout system that empowers developers to create complex and responsive designs with ease. CSS It is especially effective in creating responsive layouts that can adapt to different screen sizes. Web Designers can achieve this by defining grid templates and using media queries to adjust them as needed. CSS Grid also supports advanced features such as overlapping content, flexible row and column sizing, and content alignment. These features enable developers to create intricate multi-column layouts that were once challenging to achieve with traditional layout techniques. Overall, CSS Grid is an indispensable tool for modern web development, beneficial for both simple and complex projects.

Defining the Gap

The gap between columns in your grid layout can be defined by using grid-gap property. Let’s imagine we want to create a grid with 2 simple columns and have a 20px gap between them. In this case we would set the grid-gap property to 20px such as in the example below:

.rp_container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 20px;
}

Furthermore, we can also add a gap between our rows. In order to define the gap between rows in CSS Grid layout, we can use the grid-row-gap property. Our code would look like this:

.rp_container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 20px;
  grid-row-gap: 30px;
}

We can also combine grid-gap and grid-row-gap to just grid-gap with two values. A grid with 20px gap between columns and 30px gap between rows would look like this:

.rp_container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 20px 30px;
}

 

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Zion Builder

More from my blog

Website mockup of a construction company
Website mockup of a wedding planner company

I Develop Pixel-Perfect WordPress Websites

I’m an expert in creating top-performing, fully optimized WordPress websites that are customized to suit your specific needs. Whether you need an online store, a membership site, an LMS platform, or any other type of website, I have the knowledge and expertise to deliver results that exceed your expectations.

Testimonial From My Clients

    Would you like to chat?