gpt4 book ai didi

jquery - 砌体 : Same Column width in fluid div

转载 作者:太空宇宙 更新时间:2023-11-03 20:17:15 24 4
gpt4 key购买 nike

我正在尝试制作一个具有砖石效果的博客页面。检查这个 fiddle http://jsfiddle.net/V3rJt/

我面临的问题是,假设我的最大宽度为 1080 像素,并且我想要 3 个具有相同装订线空间的相等列,那么它的工作正常没问题。

但是,当我调整浏览器窗口大小时,我希望布局在 2 个相等的列上切换(必须填充现在可用的空间,它的宽度正在缩小)并进一步到一列博客文章。

请看下图

enter image description here

如果有人能帮我解决这个问题那就太好了。抱歉我的英语不好,我不会说英语。

HTML

<div class="section_bg">
<div class="insection_bg sparq_blog js-masonry" data-masonry-options='{ "columnWidth": 60, "gutter": 10 }'>
<div class="blogpost">
<img src="http://placehold.it/200x200" />
<h2>Blog post title</h2>
<span class="blogpost_date">17th August 2013</span>
<p class="sparq_ex">Lorem ipusm is a great dummy text to place for in blog post and any other contentLorem ipusm is a great dummy text to place for in blog post and any other content..</p>
<a class="readmore" href="">Read More</a>
</div>
<div class="blogpost">
<img src="http://placehold.it/200x200" />
<h2>Blog post title</h2>
<span class="blogpost_date">17th August 2013</span>
<p class="sparq_ex">Lorem ipusm is a great dummy text to place for in blog post and any other content.</p>
<a class="readmore" href="">Read More</a>
</div>
<div class="blogpost">
<img src="http://placehold.it/200x200" />
<h2>Blog post title</h2>
<span class="blogpost_date">17th August 2013</span>
<p class="sparq_ex">Lorem ipusm is a great dummy text to place for in blog post and any other content.</p>
<a class="readmore" href="">Read More</a>
</div>
<div class="blogpost">
<img src="http://placehold.it/200x200" />
<h2>Blog post title</h2>
<span class="blogpost_date">17th August 2013</span>
<p class="sparq_ex">Lorem ipusm is a great dummy text to place for in blog post and any other content.</p>
<a class="readmore" href="">Read More</a>
</div>
</div>
</div>

CSS

.section_bg {
padding: 100px 0;
overflow: hidden;
background: #f7f6f6;

}
.insection_bg {
max-width: 1080px;
margin: 0 auto;
}
.blogpost {
background: #ffffff;
max-width: 26%;
padding: 20px;
float: left;
margin-bottom: 25px;
box-shadow: 0px 2px 2px -1px #ccc;
}
.blogpost img {
display: block;
margin: 0 auto;
width: 100%;
}
.masonry .blogpost {
margin-bottom: 10px;
background: #D26;
border: 2px solid #333;
border-color: hsla(0, 0%, 0%, 0.5);
border-radius: 5px;
}

最佳答案

与其根据特定宽度调整列的大小(如在 jsfiddle 中所做的那样),不如使用文档中指定的元素大小调整:http://masonry.desandro.com/options.html#element-sizing

然后列宽将从元素的大小中提取(然后您可以通过 CSS 将其设置为页面宽度的百分比)。然后您可以使用媒体查询根据屏幕大小更改每个元素的宽度。文档中解释得很清楚。

这是给你的 fiddle :http://jsfiddle.net/V3rJt/3/

JavaScript:

$(document).ready(function() {

function masonry() {
//masonry
var container = document.querySelector('.js-masonry');
var msnry = new Masonry( container, {
itemSelector: '.blogpost',
columnWidth: '.blogpost'
});

};

masonry();

});

CSS:

/* I also used box-sizing:border-box; because it makes the sizing easier with % and px */

.blogpost {
background: #ffffff;
width: 31%;
margin:0 1% 25px;
padding: 20px;
float: left;
box-shadow: 0px 2px 2px -1px #ccc;
}


@media (max-width: 600px) {
/* 10 columns for larger screens */
.blogpost { width: 48%; }
}

关于jquery - 砌体 : Same Column width in fluid div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18403524/

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