上下边框之间的空白

Whitespace between borders above and below

我正在处理 CSS 中的内部边界。我正在尝试为我的网站上的图像网格复制此布局:

我无法重新创建水平和垂直边框不相互接触的方式,如此处以红色突出显示:

这是我得到的最接近的:

(复制纽约时报的代码在这里没有帮助,因为它们有不同的设置。上边框是另一个 div 的下边框。下边框是另一个 div.)

我意识到边框在一侧接触的原因是因为我使用了填充而不是边距。但是我还有其他选择吗?

我的问题是:怎样才能让边框不碰到水平线?

一张卡片的摘录

/* @media (min-width: 765px) { */
  .cards {
    display: flex;
    flex-wrap: wrap;
    margin-top: 1.1rem;
  }

  .cards article {
    border-right: 1px solid #e2e2e2;
    box-sizing: content-box;
    flex-grow: 1;
    width: 28%;
    border-top: 1px solid #e2e2e2;
    padding: 1.1rem;
    padding-bottom: 0;
    margin-top: 1.2rem;
  }

  .cards article:nth-child(1),
  .cards article:nth-child(2),
  .cards article:nth-child(3) {
    border-top: none;
    padding-top: 0;
  }

  .cards article:nth-child(3n) {
    border-right: none;
    padding-right: 0;
  }

  /* TODO formulate expression */
  .cards article:nth-child(1),
  .cards article:nth-child(4),
  .cards article:nth-child(7),
  .cards article:nth-child(10),
  .cards article:nth-child(13),
  .cards article:nth-child(16),
  .cards article:nth-child(19) {
    padding-left: 0;
  }

  .cards-wrapper .page-title {
    margin-top: 3.2rem;
    margin-bottom: 0;
    font-size: 220%;
  }
/* } */
<article>
  <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
    <figure>
    </figure>
  </a>
  <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
  <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
  <p class="description">@ Acros</p>
</article>

根据您当前的 HTML 结构,我将使用 ::after 伪元素来实现此目的。

.cards {
  display: flex;
  flex-wrap: wrap;
  margin-top: 1.1rem;
}

.cards article {
  position: relative;
  border-right: 1px solid #e2e2e2;
  box-sizing: content-box;
  flex-grow: 1;
  width: 28%;
  padding: 1.1rem;
  margin: 1.1rem 0;
}

.cards article::after {
  content: '';
  position: absolute;
  bottom: -1.1rem;
  left: 0;
  display: block;
  width: 101%;
  height: 1px;
  background: #e2e2e2;
}

.cards article:nth-child(1),
.cards article:nth-child(2),
.cards article:nth-child(3) {
  border-top: none;
  padding-top: 0;
}

.cards article:nth-child(3n) {
  border-right: none;
  padding-right: 0;
}


/* TODO formulate expression */

.cards article:nth-child(1),
.cards article:nth-child(4),
.cards article:nth-child(7),
.cards article:nth-child(10),
.cards article:nth-child(13),
.cards article:nth-child(16),
.cards article:nth-child(19) {
  padding-left: 0;
}

.cards-wrapper .page-title {
  margin-top: 3.2rem;
  margin-bottom: 0;
  font-size: 220%;
}
<div class="cards">
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
  <article>
    <a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">
      <figure>
      </figure>
    </a>
    <p class="date"><time datetime="2022-03-18">18. mars 2022</time></p>
    <h2 itemprop="headline"><a itemprop="url" href="/foto/ullandhaug-tirsdag-ettermiddag/">Ullandhaug, tirsdag ettermiddag</a></h2>
    <p class="description">@ Acros</p>
  </article>
</div>