【发布时间】:2016-05-23 04:03:18
【问题描述】:
我正在寻找最简单的方法来对以下响应式 flexbox 表上的行进行斑马条纹处理。
换句话说,本例中的第 2 行和第 4 行,但不受限制,我不知道会有多少行,因为这是用于 CMS 系统中的可重用组件。
HTML 不能更改,但行数和列数会经常更改。我很高兴对列而不是行设置限制。
有没有办法在纯 CSS 中做到这一点?
.Rtable {
display: flex;
flex-wrap: wrap;
}
.Rtable-cell {
box-sizing: border-box;
flex: 33.33%;
margin: -1px 0 0 -1px;
padding: 5px 10px;
border: solid 1px slategrey;
}
h3 { margin: 0; }
@media all and (max-width: 500px) {
.Rtable {
display: block;
}
}
<div class="Rtable">
<div style="order:1;" class="Rtable-cell"><h3>Eddard Stark</h3></div>
<div style="order:2;" class="Rtable-cell">Has a sword named Ice</div>
<div style="order:3;" class="Rtable-cell">No direwolf</div>
<div style="order:4;" class="Rtable-cell">Male</div>
<div style="order:5;" class="Rtable-cell"><strong>Lord of Winterfell</strong></div>
<div style="order:1;" class="Rtable-cell"><h3>Jon Snow</h3></div>
<div style="order:2;" class="Rtable-cell">Has a sword named Longclaw</div>
<div style="order:3;" class="Rtable-cell">Direwolf: Ghost</div>
<div style="order:4;" class="Rtable-cell">Male</div>
<div style="order:5;" class="Rtable-cell"><strong>Knows nothing</strong></div>
<div style="order:1;" class="Rtable-cell"><h3>Arya Stark</h3></div>
<div style="order:2;" class="Rtable-cell">Has a sword named Needle</div>
<div style="order:3;" class="Rtable-cell">Direwolf: Nymeria</div>
<div style="order:4;" class="Rtable-cell">Female</div>
<div style="order:5;" class="Rtable-cell"><strong>No one</strong></div>
</div>
【问题讨论】:
-
我们能否澄清一下: 1. 你真的是说列数会改变吗?您的数据似乎有规律。 2. 为什么不能用桌子?与流行的看法相反,表格也可以是响应式的。 3.你意识到如果所有的子元素都具有相同的类,你可以不用类而使用诸如
.Rtable>div之类的选择器?
标签: html css css-selectors flexbox