使浏览器包装表格单元格

时间:2012-11-27 22:22:56

标签: html css css3

我有这段代码

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个表格创建一个新行。

谢谢!

P.S。连续单元格只有4个位置。

1 个答案:

答案 0 :(得分:2)

的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;
}