gpt4 book ai didi

javascript - 是否可以精确地居中 Masonry.js 内容?

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

我正在尝试使用 Masonry 插件构建一到四列的布局 - 每页设计可变。到目前为止,我很喜欢它的工作原理。

然而,它留下了一个非常恼人的差距,我似乎无法摆脱配置。

要指出 - 它已经在页面上居中。但是,在居中的 block 内,内容显示为左对齐。

Masonry problem example

内部内容也没有边距。 Masonry 被初始化为:

$('.msgblock').masonry({
columnWidth: '.grid-item',
gutter: 8,
itemSelector: '.grid-item',
fitWidth: true,
resize: false
});

我在 CSS 中完全消除了 .msgblock 宽度,因此它由插件提供。

.msgblock {
min-height: 100%;
margin: 0 auto;
z-index: 1;
}

.grid-item {
min-height: 100%;
padding-top: 10px;
}

最佳答案

尝试使用 flex 方法:

.grid-item {
min-height: 100%;
padding-top: 10px;
display: flex;
align-items: center;
justify-content: center;
}

更新:要填补空白,您可以使用stretch 选项。这是一个 fiddle

.grid-item {
background: ghostwhite;
box-sizing: border-box;
padding: 10px;
display: inline-flex;
min-height: 200px;
align-self: stretch;
flex-direction: column;
flex: 1 0 auto;
outline: 1px solid #dde;
}

.grid-item:nth-child(2n+1) {
background: ghostwhite;
}

.grid-item:nth-child(2n) {
background: #eef;
}

.row {
width: 100%;
background: gray;
display: flex;
flex-wrap: wrap;
}
<div class="row">
<div class="grid-item" style='min-width:60%'>Cell 1</div>
<div class="grid-item" style='min-width:35%'>Cell 2</div>
<div class="grid-item" style='min-width:45%'>Cell 3</div>
<div class="grid-item" style='min-width:25%'>Cell 4</div>
<div class="grid-item" style='min-width:15%'>Cell 5</div>
</div>

关于javascript - 是否可以精确地居中 Masonry.js 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42338445/

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