0

Is there anyway to tell my gp1 class column to start at grid position 1 and end at position max - 1, bearing in mind this is a dynamic grid?

.widthContainer {
  width:400px;
  height:300px;
  background-color:#eee;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 50px);
  grid-template-rows: repeat(auto-fit, 25px);
  min-height: 98%;
}

.grid>div {
  grid-column: 1/-1;
  grid-row: 1/-1;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  grid-template-rows: repeat(auto-fill, minmax(25px, 1fr));
  display: grid;
}

.gp1 {
  background-color: #aaa;
  grid-row-start: 2;
  grid-row-end: 4;
  grid-column-start:2;
  grid-column-end:4;
}
<div class="widthContainer">
  <div class="grid">
    <div class="bkg">
      <div class="gp1">
        <div>
          <p>content</p>
        </div>
      </div>
    </div>
  </div>
</div>
doğukan
  • 23,073
  • 13
  • 57
  • 69
jamheadart
  • 5,047
  • 4
  • 32
  • 63
  • 1
    you are already doing it with `grid-column: 1/-1;` so use `grid-column: 2/-2;` – Temani Afif Jul 01 '20 at 14:51
  • Oh THAT'S what that is doing, shorthand for start/end FFS. Still learning css-grid - I'd read that somewhere and it had just skipped my mind because I was so wrapped up in all the wrappers. – jamheadart Jul 01 '20 at 14:52
  • grid-column: 1/-2;* ("start at grid position 1 and end at position max - 1") – VXp Jul 01 '20 at 14:55

1 Answers1

2

Yes. Use -2 for grid-column-end

.widthContainer {
  width: 400px;
  height: 300px;
  background-color: #eee;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 50px);
  grid-template-rows: repeat(auto-fit, 25px);
  min-height: 98%;
}

.grid>div {
  grid-column: 1/-1;
  grid-row: 1/-1;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  grid-template-rows: repeat(auto-fill, minmax(25px, 1fr));
  display: grid;
}

.gp1 {
  background-color: #aaa;
  grid-row-start: 2;
  grid-row-end: 4;
  grid-column-start: 2;
  grid-column-end: -2;
}
<div class="widthContainer">
  <div class="grid">
    <div class="bkg">
      <div class="gp1">
        <div>
          <p>content</p>
        </div>
      </div>
    </div>
  </div>
</div>
doğukan
  • 23,073
  • 13
  • 57
  • 69