gpt4 book ai didi

html - css 不同高度 div 网格空间

转载 作者:太空宇宙 更新时间:2023-11-04 10:31:15 25 4
gpt4 key购买 nike

我的问题与此类似:CSS different height div elements causing grid spacing .但是有不同数量的div。

请给点意见!

我用js把方框做成绝对位置。但是,有时 div 的位置不正确!

       <?php foreach ($list as $row): ?> 
<div class="box col-md-3 col-lg-3 col-sm-2 col-xs-2" >

<a href="single/<?php echo $row->id; ?>">
<img class="img-thumbnail img-avatar" src="/images/<?php echo $row->avatar; ?>" alt="photo"/>
</a>
<br />
<label class="label label-info">
<?php echo $row->name; ?>
</label>
<br/>
<label class="label label-info">
age: <?php echo $row->age; ?>
</label>
</div>
<?php endforeach; ?>


<script>
$(document).ready(function () {


var width = $(window).width();
var height = $(window).height();
var dw = Math.floor(width / 3) - 5;
$(".div-candidate").width(dw);
var cds = $(".box");
var n = cds.size();
var w = dw;
var h1 = 0;
var h2 = 0;
var h3 = 0;
for (i = 0; i < n; i++)
{
// var d = $(cds)[i];

if (i % 3 === 0) {
var t1 = h1;
h1 = h1 + $(cds[i]).height() + 5;
$(cds[i]).css({"top": t1, "left": 0});
}

if (i % 3 === 1) {
var t2 = h2;
h2 += $(cds[i]).height() + 5;
$(cds[i]).css({"top": t2, "left": w + 5});
}

if (i % 3 === 2) {
var t3 = h3;
h3 += $(cds[i]).height() + 5;
$(cds[i]).css({top: t3, left: (w + 5) * 2});
}

}
var m = Math.max(h1, h3, h2);
$("#div-container").height(m);

});
</script>

最佳答案

我通过添加 windows.load() 解决了我的问题

关于html - css 不同高度 div 网格空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36483326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com