我正在尝试在每一行之后使用内容居中对齐的 CSS 网格制作一个 border-bottom
。我无法理解它。
我想要 .line
填充整个 .wrapper
容器的宽度。
我怎样才能做到这一点?
这是代码:
* {
box-sizing: border-box;
}
.outer {
width: 80%;
margin: 0 auto;
}
.wrapper {
border: 2px solid #f76707;
border-radius: 5px;
background-color: #fff4e6;
display: grid;
grid-template-columns: repeat(3, auto) max-content;
justify-content: center;
}
.wrapper>div:not(.line) {
border: 2px solid #ffa94d;
border-radius: 5px;
background-color: #ffd8a8;
padding: 1em;
color: #d9480f;
}
.line {
grid-column-start: 1;
grid-column-end: 6;
height: 2px;
border-bottom: 1px solid black;
width: 100%;
}
<div class="outer">
<div class="wrapper">
<div>1111111</div>
<div>222</div>
<div>3333333333</div>
<div class="line"></div>
<div>4444</div>
<div>555555555</div>
<div>99999999999</div>
</div>
</div>
原文由 repo 发布,翻译遵循 CC BY-SA 4.0 许可协议
代替
justify-content
将内容居中,您可以在内容前后添加额外的列,两者都使用1fr
。然后将第一个
div
和 --- 放在.line
div
之后到第二列的开头。小提琴