1

Problem

I want to change only gap
I'm using CSS grid.
I want to make only grid-gap variable without changing the internal position of grid.
Somehow tags don't do left side. I also want this to be left justified.

▼ In other words, I want to do this.


What I want to do

like this How can I do this?


Code

html { font-size: 62.5%; }
body { display: block; margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; font: inherit; vertical-align: baseline; background: transparent; box-sizing: border-box; }  /* reset */

#items {
  display: grid;
  grid-gap: 3.8rem 4.6rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.item {
  text-align: center;
}
.item img {
  max-width: 100%;
  height: auto;
}
.item h2 {
  font-size: 1.6rem;
  margin-top: 1.6rem;
  margin-bottom: 1.5rem;
}
.item p {
  font-size: 1.5rem;
  margin-bottom: .8rem;
}
.item h2, .item p, .item span {
  font-family: 'OsakaBit';
  text-align: left;
}
.item span {
  display: inline-block;
  font-size: 1.1rem;
  border: .1rem solid black;
  border-radius: .3rem;
  margin-right: .6rem;
  margin-bottom: .5rem;
  padding: .3rem;
}
<div id="items">
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210318.png">
      <h2>Title</h2>
      <p>Easy explanation</p>
      <span>tag</span>
      <span>tags</span>
      <span>of</span>
      <span>various</span>
      <span>lengths</span>
      <span>tag</span>
      <span>tag</span>
      <span>tag</span>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210315.png" alt="b" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210313.png" alt="c" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210310.png" alt="d" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210308.png" alt="e" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210354.png" alt="f" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210352.png" alt="g" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
    <section class="item">
      <img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190312/20190312210349.png" alt="h" />
      <h2>Title</h2>
      <p>Easy explanation</p>
    </section>
  </div>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
POP
  • 631
  • 2
  • 7
  • 19
  • Grid-gap is not variable. What you seem to want is probably only achievable with a change to the HTML and use flexbox. – Paulie_D Mar 12 '19 at 15:15

0 Answers0