尝试这个...
HTML/PHP
<div id="index-gallery">
<?php $ires3 = mysql_query("select `id`,`mp4`,`cover` from `d2pxhd`.`videos` WHERE `duration`>'0' AND `active`='1' AND `suspended`='0' AND `add_date`<now() ORDER BY `add_date` DESC limit 24",$db);
while ($img3 = mysql_fetch_assoc($ires3)) : ?>
<div class="img-box">
<a href="/?play=<?=base64_encode(preg_replace('/\s+/', '', $img3['id']));?>&start=1">
<img style="margin:20px 2px;" width="118" height="100" border="0" src="<?=$img3['cover']."002.jpg";?>">
</a>
<p>SUBTITLE HERE!!!</p>
</div>
<?php endwhile; ?>
<div class="clear-both"></div>
</div>
CSS
#index-gallery {
width:100%;
}
.img-box {
float:left;
padding:5px;
margin:10px 0 0 0;
}
.img-box a, .img-box img {
display:block;
}
.clear-both {
clear:both;
}
每行中的固定列数(以获得更一致的格式)
<?php $cols = 4; ?>
<div id="index-gallery">
<?php $ires3 = mysql_query("select `id`,`mp4`,`cover` from `d2pxhd`.`videos` WHERE `duration`>'0' AND `active`='1' AND `suspended`='0' AND `add_date`<now() ORDER BY `add_date` DESC limit 24",$db); ?>
<?php while ($img3 = mysql_fetch_assoc($ires3)) : ?>
<?php for($i=1; $i <= $cols; $i++) : ?>
<div class="img-box">
<a href="/?play=<?=base64_encode(preg_replace('/\s+/', '', $img3['id']));?>&start=1">
<img style="margin:20px 2px;" width="118" height="100" border="0" src="<?=$img3['cover']."002.jpg";?>">
</a>
<p>SUBTITLE HERE!!!</p>
</div>
<?php if($i == $cols) : ?>
<div class="clear-both"></div>
<?php $i=1; endif; ?>
<?php endfor; ?>
<?php endwhile; ?>
<div class="clear-both"></div>
</div>