【发布时间】:2020-08-11 22:15:33
【问题描述】:
我有一个 div 模板,并且我通过 PHP 生成了多个具有动态内容的 div。 现在的问题是我的 div 在不规则的位置创建(检查下面的图片),我想要的是。 “我希望每行有四个大小相等的 div,每个 div 必须并排,每个 div 之间需要保持一个小间隙”。
这是我的 div。
<div class="row" id="except">
<div class="column">
<div class="card">
<h1><?php echo"$value"; ?></h1>
<h3><?php echo"$description";?></h3>
<h3><?php echo"$index";?></h3>
</div>
</div>
</div>
这是每个 div 的 CSS。
<style>
#except{
width:1200px;
height:500px;
margin-left:160px;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Float four columns side by side */
.column {
float: left;
width: 25%;
padding: 0 10px;
}
/* Remove extra left and right margins, due to padding */
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive columns */
@media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 20px;
}
}
/* Style the counter cards */
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 1);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
transition: width 2s,height 4s;
transition-timing-function: ease-in-out;
}
.card:hover{
background-color: lightgreen;
transition-timing-function: ease-in-out;
width: 300px;
height: 300px;
}
</style>
【问题讨论】:
-
只需复制列 div 并在行 div 中粘贴 4 次,我认为您是在循环中创建多行。
-
4 不固定。我想创建“N”个 div。 “N”是通过PHP检索到的动态数
标签: html css user-interface bootstrap-4 flexbox