gpt4 book ai didi

javascript - 均匀分布箱子,但每个箱子之间留有余量

转载 作者:行者123 更新时间:2023-11-28 12:03:52 26 4
gpt4 key购买 nike

这是一个类似问题的 fiddle : http://jsfiddle.net/DougCassidy/Gawe7/它工作得很好,但是,我希望盒子之间有一些很好的间距。如果右边距被视为框之间的最小间距会很好,这样如果间距低于该值,它会将所有内容向下移动一行。此外,当前行中的最后一个框不应有右边距。

然后是一些底边距。要么固定数量就可以,要么等于当前水平间距的数量也不错。

$(new Array(9).join('<div class="invisible"></div>\n')).insertBefore('.stretch');

$(window).on('resize', function() {
$('#container').height($('.box').last().position().top + $('.box').last().outerHeight());

//make it still justify when there's only one row
if ($('.box').first().position().top == $('.box').last().position().top) {
$('.invisible').hide();
} else {
$('.invisible').show();
}
}).resize();

最佳答案

你不需要 JavaScript,只需要负边距:

http://codepen.io/cimmanon/pen/iHGCd

.gallery {
margin: -5px;
display: -ms-flexbox;
display: -webkit-flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
@supports (flex-wrap: wrap) {
.gallery {
display: flex;
}
}

.gallery img {
margin: 5px;
}

HTML:

<div class="gallery">
<img src="http://placehold.it/200x100" />
<!-- etc -->
</div>

因为边距不会在 flex 元素上折叠,所以如果您像这样在所有边上添加边距,效果最好。

关于javascript - 均匀分布箱子,但每个箱子之间留有余量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19770042/

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