HTML / CSS:列之间的边框

huangapple go评论68阅读模式
英文:

HTML / CSS: Borders between columns

问题

我正在尝试使用Flexbox创建列布局,并希望在每个列之间有垂直的全高度边框。

这是我试图创建的效果 — BORDERS IMAGE

.testing {
  display: flex;
  flex-direction: row;
  padding: 10%;
  flex-wrap: wrap;
  background-color: red;
  height: 20%;
}

.testing > div {
  width: 100px;
  background-color: green;
  margin: 10px;
  padding: 10px;
  text-align: center;
}
<div class="testing">
  <div class="col">
    00
  </div>
  <!-- 其他列 -->
</div>

我在某处看到最好使用Flexbox来实现这个效果,但我找不到与边框相关的属性?

英文:

I'm trying to create a column layout using Flexbox and would like there to be vertical, full-height borders in between each of the columns.

Here is the kind of thing I'm trying to produce — BORDERS IMAGE

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.testing {
  display: flex;
  flex-direction: row;
  padding: 10%;
  flex-wrap: wrap;
  background-color: red;
  height: 20%;
}

.testing &gt; div {
  width: 100px;
  background-color: green;
  margin: 10px;
  padding: 10px;
  text-align: center;
}

<!-- language: lang-html -->

&lt;div class=&quot;testing&quot;&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

I read somewhere that it is best to use Flexbox to achieve this, yet i cant find any properties relating to borders?

答案1

得分: 0

玩一下gap属性。

    .testing {
      display: flex;
      flex-direction: row;
      padding: 10%;
      flex-wrap: wrap;
      /* 背景颜色: 红色; */
      height: 20%;
      gap: 1px;
    }

    .testing > div {
      width: 100px;
      背景颜色: 绿色;
      /* 外边距: 10px; */
      padding: 10px;
      文本对齐: 居中;
      边框: 10px 实线 红色;
    }
    <div class="testing">
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
      <div class="col">
        00
      </div>
    </div>
英文:

Play around with the gap property.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.testing {
  display: flex;
  flex-direction: row;
  padding: 10%;
  flex-wrap: wrap;
  /* background-color: red; */
  height: 20%;
  gap: 1px;
}

.testing &gt; div {
  width: 100px;
  background-color: green;
  /* margin: 10px; */
  padding: 10px;
  text-align: center;
  border: 10px solid red;
}

<!-- language: lang-html -->

&lt;div class=&quot;testing&quot;&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
  &lt;div class=&quot;col&quot;&gt;
    00
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月13日 18:19:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242216.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定