如何解决如何让布局与 Isotope 插件一起使用?
我正在使用 Isotope,但布局一团糟。我尝试使用浮动,现在我尝试使用 CSS 网格,但布局不合作。有没有更好的方法让布局看起来正确?我试图让这些项目的大小完全相同,并且在桌面上每行四个。
$(document).ready(function() {
$grid = $('.product').isotope({
itemSelector: '.itemBox',layoutMode: 'fitRows'
});
$filters = $('.list');
$filters.click(function() {
$value = $(this).attr('data-filter');
$grid.isotope({ filter: '.' + $value });
});
});
ul {
display: flex;
list-style: none;
justify-content: center;
margin-top: 25px;
}
ul > li {
margin-left: 15px;
cursor: pointer;
padding: 0.5rem 1rem;
background-color: crimson;
color: white;
font-family: 'Calibri',sans-serif;
}
.product {
display: grid;
grid-template-columns: repeat(4,1fr);
grid-gap: 1rem;
width: 90%;
margin: 0 auto;
}
.itemBox {
grid-column: span 1;
}
.itemBox > img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
@media screen and (max-width: 1024px) {
.product {
grid-template-columns: repeat(3,1fr);
}
}
@media screen and (max-width: 768px) {
.product {
grid-template-columns: repeat(1,1fr);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="product">
<div class="itemBox phone"><img src="img (1).jpg" alt=""></div>
<div class="itemBox camera"> <img src="img (3).jpg" alt=""></div>
<div class="itemBox watch"><img src="img (6).jpg" alt=""></div>
<div class="itemBox camera"> <img src="img (3).jpg" alt=""></div>
<div class="itemBox watch"><img src="img (6).jpg" alt=""></div>
<div class="itemBox camera"> <img src="img (3).jpg" alt=""></div>
<div class="itemBox watch"><img src="img (6).jpg" alt=""></div>
<div class="itemBox watch"><img src="img (6).jpg" alt=""></div>
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。