Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Weird gap in the rightmost side in grid layout

This is the photo

The picture of the problem

I have this CSS code here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        .container{
            display: grid;
            grid-template-columns: 20% 45% 20%;
            grid-column-gap: 5%;
            border: 1px solid black;
        }
        .left{
            border: 2px solid red;
            height: 300px;
        }
        .middle{
            border: 2px solid blue;
            height: 300px;
        }
        .right{
            border: 2px solid green;
            height: 300px;
        }

As you can see in the rightmost side of the photo, there’s some weird gap there. I want it so that there will be no gap in there like in the leftmost side. How do I remove the gap?

I should also ask this here since I’m new at this CSS.

How should I better write my code.

How to also select multiple classes so I don’t have to repeat the height at the 3 classes.

>Solution :

The below code will help you to solve your problem.

.container {
  display: grid;
  grid-template-columns: 20% 50% 20%;
  grid-column-gap: 5%;
  border: 1px solid black;
}
.col {
  height: 300px;
}
.col:nth-child(1) {
  border: 2px solid red;
}
.col:nth-child(2) {
  border: 2px solid blue;
}
.col:nth-child(3) {
  border: 2px solid green;
}
<div class="container">
  <div class="col"></div>
  <div class="col"></div>
  <div class="col"></div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading