html - css网格如何在行之间添加线?

标签 html css reactjs html-table css-grid

我正在使用 CSS 网格制作表格。我无法在行中添加边框线。列之间有间隙。应该是图片中的样子

enter image description here

这是我在单元格中添加 border-bottom 时得到的结果:

enter image description here

const TableWrapperUI = styled.div`
  display: grid;
  box-sizing: border-box;
  width: 100%;
  border: 1px solid #dbeaf4;
  grid-template-columns: repeat(
    ${props => props.columns && props.columns},
    fit-content(400px)
  );
  justify-items: center;
  padding: 5px;
  justify-content: space-between;
  > span {
    justify-self: left;
    border-bottom: 1px solid red;
  }
`;

您可以在这里查看:https://codesandbox.io/s/goofy-easley-w5rrg

最佳答案

如果你想保持元素之间的差距,你可以在每一行之间添加一个空元素并将其拉伸(stretch)到容器的整个宽度(使用 grid-column 属性)然后添加一个边框

您可以在此处查看示例:

.container{
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-gap: 10px;
}

.row-border{
    border-top: 2px solid gray;
    grid-column: 1 / 5; /* this code makes the row stretch to entire width of the container */
}
<div class="container">
  <div>col 1 of row 1</div>
  <div>col 2 of row 1</div>
  <div>col 3 of row 1</div>
  <div>col 4 of row 1</div>
  
  <div class="row-border"></div>

  <div>col 1 of row 2</div>
  <div>col 2 of row 2</div>
  <div>col 3 of row 2</div>
  <div>col 4 of row 2</div>

  <div class="row-border"></div>

  <div>col 1 of row 3</div>
  <div>col 2 of row 3</div>
  <div>col 3 of row 3</div>
  <div>col 4 of row 3</div>

  <div class="row-border"></div>

  <div>col 1 of row 4</div>
  <div>col 2 of row 4</div>
  <div>col 3 of row 4</div>
  <div>col 4 of row 4</div>
</div>

关于html - css网格如何在行之间添加线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56900389/

相关文章:

html - 使用单指手势滚动 <object> 元素 - IPAD 不工作

javascript - 读取加载页面时返回的脚本的属性

javascript - React.createClass 不是一个函数,可能是 webpack 编译错误

javascript - React Native - 如何使 TouchableOpacity 的一部分不可按下

html - 为什么添加旋转动画会偏移我的图像?

html - 如何将选择中的所选元素添加到所选字段

php - 使用图像作为文本

javascript - 将宽度设置为 100% 以使其在 js 中响应

css - 滑出控件 UI 中的问题

javascript - 如何处理冲突的库? - mathquill 与 bootstrap