5

我有这个代码

HTML:
<div id="table">
    <div class="table-cell"></div>
    <div class="table-cell"></div>
    <div class="table-cell"></div>
    <div class="table-cell"></div>
    <div class="table-cell"></div>
    <div class="table-cell"></div>
    <div class="table-cell"></div>
    <div class="table-cell"></div>
</div>

CSS:
#table {
    display: table;
    width: 940px;
    table-layout: fixed;
}
.table-cell {
    display: table-cell;
    overflow: hidden;
    width: 220px;
    height: 282px;
    padding: 9px 10px;
}

是否可以在每添加 4 个后让浏览器包装表格单元格。我的意思是每 4 个表格单元创建新行。

谢谢!

PS 一行中只有 4 个单元格的位置。

4

1 回答 1

3

CSS:

#table {
    display: table;
    width: 940px;
    table-layout: fixed;
}
.table-row
{display:table-row;}

.table-cell {
    display: table-cell;
    overflow: hidden;
    width: 220px;
    height: 282px;
    padding: 9px 10px;
}

html:

<div id="table">
    <div class="table-row" >
        <div class="table-cell">1</div>
        <div class="table-cell">2</div>
        <div class="table-cell">3</div>
        <div class="table-cell">4</div>
    </div>
    <div class="table-row" >
        <div class="table-cell">1a</div>
        <div class="table-cell">2a</div>
        <div class="table-cell">3a</div>
        <div class="table-cell">4a</div>
    </div>
</div>

你说需要自动:

您可以将 css 更改为:

#table {
    display: table;
    width: 960px !important;
    table-layout: fixed;
}
.table-cell {
    float: left;
    display: table-cell;
    overflow: hidden;
    width: 220px;
    height: 282px;
    padding: 9px 10px;
}
于 2012-11-27T22:31:21.917 回答