gpt4 book ai didi

javascript - JQuery Packery 的中心容器?

转载 作者:行者123 更新时间:2023-11-28 20:20:33 24 4
gpt4 key购买 nike

我使用JQuery Packery效果很好。

我想到的问题是如何使项目容器在页面上居中?

<div id="container">
<div class="item">...</div>
<div class="item w2">...</div>
<div class="item">...</div>
...
</div>

我尝试过CSS:

#container {
marin: 0 auto;
}

但这不起作用。

最佳答案

DeSandro 已经有一个居中包装布局的示例。

示例为here .

基本上它只是通过 CSS 居中。我也将代码复制到这里:

HTML:

<h1>Packery - centered</h1>
<div class="packery js-packery" data-packery-options='{ "gutter": ".gutter-sizer", "itemSelector": ".item", "columnWidth": ".grid-sizer" }'>
<div class="gutter-sizer"></div>
<div class="grid-sizer"></div>
<div class="item w2"></div>
<div class="item"></div>
<div class="item w2 h2"></div>
<div class="item"></div>
<div class="item w2"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item"></div>
</div>

CSS:

* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

.packery {
background: #FDD;
background: hsla(45, 100%, 40%, 0.2);
max-width: 480px;
margin: 0 auto;
}

/* clearfix */
.packery:after {
content: ' ';
display: block;
clear: both;
}

.gutter-sizer {
width: 2%;
}

.grid-sizer {
width: 18.4%;
}

.item {
width: 18.4%;
height: 60px;
float: left;
background: #C09;
border: 4px solid #333;
border-color: hsla(0, 0%, 0%, 0.3);
}

.item.w2 { width: 38.8%; background: #9C0; }
.item.h2 { height: 120px; background: #0C9; }

关于javascript - JQuery Packery 的中心容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18411128/

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