Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing grid gaps

Tags:

html

css

css-grid

I have a div with elements aligned as a row, this is the css class for it:

.myRow {
  display: grid;
  grid-template-columns: 0.1fr 0.1fr 2fr 3fr 2fr;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  justify-content: center;
  padding: 10px;
}
<div class="myRow">
  <div style="color:blue; width: 5px;">aa</div>
  <div style="color:red;">bb</div>
  <div style="color:green;">ccc</div>
  <div style="color:orange;">ddd</div>
  <div style="color:purple;">eee</div>
</div>

I want to be able to remove the first two gaps and keep the rest of the gaps, like how grid-template-columns works.

enter image description here

Is it possible to do this with grid?

Edit: I want it to be like this:

enter image description here

like image 297
shinzou Avatar asked Mar 07 '23 03:03

shinzou


1 Answers

Add negative right margin whose value is equal to grid gap

.myRow {
  display: grid;
  grid-template-columns: 0.1fr 0.1fr 2fr 3fr 2fr;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  justify-content: center;
  padding: 10px;
}

.margin {
  margin-right: -10px
}
<div class="myRow">
  <div class="margin" style="color:blue; width: 5px; ">aa</div>
  <div class="margin" style="color:red;">bb</div>
  <div style="color:green;">ccc</div>
  <div style="color:orange;">ddd</div>
  <div style="color:purple;">eee</div>
</div>
like image 86
Gautam Naik Avatar answered Mar 21 '23 02:03

Gautam Naik