[英]How do you create a grid dynamically in PHP?
I'm trying to create a mini-message board. 我正在尝试创建一个迷你留言板。 I am using divs for each of the messages but I want to organise the divs in a grid.
我正在为每个消息使用div,但是我想在网格中组织div。 The grid should be flexible and responsive meaning that the number of columns and rows should dynamically change as the screen size does.
网格应具有灵活性和响应性,这意味着列数和行数应随屏幕尺寸而动态变化。
This is what I have done so far but it does not seem to work: 这是我到目前为止所做的,但是似乎没有用:
<div class="grid-container">
<?php
while($row = $result->fetch_assoc() ){
display($row['name'],$row['date'],$row['message']);
}
}
function display($name, $date, $message){
echo '<div class="flip-card grid-item">
<div class="flip-card-inner">
<div class="flip-card-front">
<p class="message">'.$message.'</p>
</div>
<div class="flip-card-back">
<h1 class="nameTitle"> '.$name.'</h1>
<p class="dateTitle">'.$date.'</p>
</div>
</div>
</div>';
}
?>
</div>
I know that the code for the displaying the information from the database works because the divs do appear. 我知道用于显示数据库信息的代码可以正常工作,因为div确实出现了。 It's just they don't appear in a grid.
只是它们没有出现在网格中。
Thanks in advance for help! 在此先感谢您的帮助!
I would recommend you FlexBox. 我建议您使用FlexBox。
.body{
height: 100vh;
}
.column-wrapper {
height: inherit;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
.column {
background: tomato;
padding: 5px;
width: 200px;
height: 150px;
margin-top: 10px;
line-height: 150px;
color: white;
font-weight: bold;
font-size: 3em;
text-align: center;
}
</style>
A simple example here: https://jsfiddle.net/04yxfwLg/1/ 一个简单的例子在这里: https : //jsfiddle.net/04yxfwLg/1/
The trick is using justify-content
to space-around
诀窍是使用
justify-content
来space-around
More on flexbox can be found on this amazing article. 关于Flexbox的更多信息可以在这篇令人惊奇的文章中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.