Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 固定列数上的动态单元格数_Html_Css_Layout - Fatal编程技术网

Html 固定列数上的动态单元格数

Html 固定列数上的动态单元格数,html,css,layout,Html,Css,Layout,是否有可能在一个具有固定列数(比如4列)的容器中分配动态数量的单元格。我想做的是: <div class="container_4"> <div class="cell">Cell 1</div> <div class="cell">Cell 2</div> <div class="cell">Cell 3</div> <div class="cell">Cell 4&

是否有可能在一个具有固定列数(比如4列)的容器中分配动态数量的单元格。我想做的是:

<div class="container_4">
    <div class="cell">Cell 1</div>
    <div class="cell">Cell 2</div>
    <div class="cell">Cell 3</div>
    <div class="cell">Cell 4</div>
    <div class="cell">Cell 5</div>
    <div class="cell">Cell 6</div>
    <div class="cell">Cell 7</div>
</div>

如果我没弄错,这可能对你有用:

#container_4 {
    width: 400px; /* Change to your container width */
}

.cell {
    width: 25%; /* Use different percentages for a different number of columns */
    float: left;
}
然后,如果您需要单元格上的边距,请进行计算,例如:

.cell {
    width: 23%; /* 1/4 the container width - margin x 2 */
    margin: 1%; /* Your margin */
    float: left;
}
或者使用CSS3属性
框大小调整
,改为使用填充的框边距:

.cell {
    width: 25%;
    padding: 1%;
    float: left;
    /* This will make the specified with include padding's and borders */
    box-sizing: border-box; /* Standard syntax */
    -moz-box-sizing: border-box; /* Firefox */
    -webkit-box-sizing: border-box; /* Safari */
}

注意:
box size
属性在ie7上不起作用。在“怪癖”模式下,ie6使用defaul的“
边框框
”模型(有关ie6框模型错误的更多信息,请参阅)。

如果我理解正确,这可能适用于您:

#container_4 {
    width: 400px; /* Change to your container width */
}

.cell {
    width: 25%; /* Use different percentages for a different number of columns */
    float: left;
}
然后,如果您需要单元格上的边距,请进行计算,例如:

.cell {
    width: 23%; /* 1/4 the container width - margin x 2 */
    margin: 1%; /* Your margin */
    float: left;
}
或者使用CSS3属性
框大小调整
,改为使用填充的框边距:

.cell {
    width: 25%;
    padding: 1%;
    float: left;
    /* This will make the specified with include padding's and borders */
    box-sizing: border-box; /* Standard syntax */
    -moz-box-sizing: border-box; /* Firefox */
    -webkit-box-sizing: border-box; /* Safari */
}
注意:
box size
属性在ie7上不起作用。在怪癖模式下,ie6使用defaul的“
边框框
”模型(有关ie6框模型错误的更多信息,请参阅)。

CSS

CSS

集装箱宽度固定吗?集装箱宽度固定吗?感谢您的快速回复。我需要一些容器css的东西吗?这使所有项目都位于同一行。您需要指定容器的宽度。很抱歉,我之前读过你的评论,只是假设你已经这样做了。编辑了我的答案以包含最后的修复。此外,如果您还没有在页面上使用浮动,那么您可能希望在#container_4 css中包含一个“clear fix”技术。我相信IE6的行为和IE7一样,具有适当的doctype(我猜您希望在HTML代码的开头有一个doctype)。虽然是的,IE6在怪癖模式下默认会表现为边框框,非常讽刺的是…感谢您的快速回复。我需要一些容器css的东西吗?这使所有项目都位于同一行。您需要指定容器的宽度。很抱歉,我之前读过你的评论,只是假设你已经这样做了。编辑了我的答案以包含最后的修复。此外,如果您还没有在页面上使用浮动,那么您可能希望在#container_4 css中包含一个“clear fix”技术。我相信IE6的行为和IE7一样,具有适当的doctype(我猜您希望在HTML代码的开头有一个doctype)。虽然是的,IE6在怪癖模式下默认会表现为边框框,非常讽刺。。。