Bootstrap:条纹 div 表

新手上路,请多包涵

我正在使用 Bootstrap css 库。我知道如何用这个库制作条纹表,但如何制作条纹 div?

例如,在表中你会这样做:

 <table id="newtable" class="table table-bordered table-striped fixedtable">
    <thead>
        <th>Date</th>
        <th>Info</th>
        <th>Price</th>
    </thead>
    <tbody>
        <tr>
            <td colspan="3">
                <div>text 1</div>
                <div>text 2</div>
                <div>text 3</div>
                <div>text 4</div>
            </td>
        </tr>
    </tbody>
</table>

我需要像这样用 div 重复这种“样式”:

 <div class="row"><div class="col">Text 1 White BG</div></div>
<div class="row"><div class="col">Text 2 Grey BG</div></div>
<div class="row"><div class="col">Text 3 White BG</div></div>
<div class="row"><div class="col">Text 4 Grey BG</div></div>

问题是:如何制作: <div>text 1</div>, <div>text 2</div>, <div>text 3</div>, <div>text 4</div> 条纹?

原文由 Lugaru 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 328
2 个回答

Twitter Bootstrap 的条带化仅适用于表格行。因此,为了对您的 div 进行条带化,您需要将它们中的每一个添加到一个新行中。例如:

     <tr>
        <td>
            <div>text 1</div>
        </td>
    </tr>
    <tr>
        <td>
            <div>text 2</div>
        </td>
    </tr>
    ...

另外我不确定你想用 colspan="3" 实现什么。如果你想创建一个合适的表,你需要为每一列创建新的 td 。例如:

     <tr>
        <td>2013-07-22</td>
        <td>Text for info field 1</td>
        <td>9.99</td>
    </tr>

原文由 jsalonen 发布,翻译遵循 CC BY-SA 3.0 许可协议

将类图例添加到您的容器,然后对于实际在该行内的 div 中的每一行,您可以应用一种格式

CSS

.legend .row:nth-of-type(odd) div {
background-color:antiquewhite;
}
.legend .row:nth-of-type(even) div {
background: #FFFFFF;
}

<div class="container legend">
    <div class="row">
     <div class="col-sm-2">text</div>
     <div class="col-sm-2">more Text</div>
</div>
<div class="row">
     <div class="col-sm-2">text</div>
     <div class="col-sm-2">more Text</div>
 </div>
</div>

原文由 Rondakay 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题