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

how to center columns and keep min column gap in a css grid

in the example below columns should be on center of page
resizing the page all free space should be distributed around all columns equally – so including the first and the last column
min column gap – 14px
row-gap – fixed – 14px
pls help

.wrap {
   padding:0 20px;
   display:grid;
   grid-template-columns: repeat(auto-fill, minmax(100px, 120px));
   grid-column-gap:14px;
   grid-row-gap:14px;
}

.card {
  background:orange;
  height:25px;
}
<div class='wrap'>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
<div class='card'></div>
</div>

>Solution :

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

Added few rules to .wrap{…} selector. Hopefully this helps. Doesn’t do much here so test inside your actual code.

.wrap{
  padding:0 20px;
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 120px));
  grid-column-gap:14px;
  grid-row-gap:14px;
  
  // rules to center below

  width: -webkit-fill-available;
  height: -webkit-fill-available;
  justify-content: center;
  align-items:center
}

.card{
  background:orange;
  height:25px;
}
<div class='wrap'>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></div>
  <div class='card'></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