我正在尝试使用 Masonry 创建图片库,并且在调整浏览器大小时图像会重新排序。
但是,由于我为缩略图使用 150 像素的固定宽度(因此未加载实际的大图像文件),但我无法删除图像容器两侧的访问间距,因为它会缩放基于屏幕尺寸的百分比用于宽度。
网站布局如下图:
请注意,图像容器右侧有多余的间距。综上所述,
如何使容器缩放到 Masonry 图像网格的大小,因为图像容器是根据宽度通过百分比计算的?
将图像固定为 150 像素的宽度是否有意义?如果不是,哪种是显示不同尺寸屏幕缩略图的首选方法?
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App</title>
<link rel="stylesheet" href="/static/css/style.css" />
<link rel="stylesheet" href="/static/css/reset.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<script src="/static/js/jquery-1.11.0.min.js"></script>
<script src="/static/js/masonry.pkgd.min.js"></script>
</head>
<body>
<div id="wrapper">
<!-- the header and navigation -->
<div id="header">
<div id="navigation">
<ul>
<li><a href="#">Navigation1</a></li>
<li><a href="#">Navigation2</a></li>
</ul>
</div>
</div>
<!-- the content -->
<div id="content">
<!--- Image container -->
<div id="gallery_container">
<ul>
<li>
<img src="http://127.0.0.1:8001/media/images/d4RYJ4U_1.jpg" />
</li>
<li>
<img src="http://127.0.0.1:8001/media/images/hJLK7.jpg" />
</li>
<li>
<img src="http://127.0.0.1:8001/media/images/vx7IB5M.jpg" />
</li>
<li>
<img src="http://127.0.0.1:8001/media/images/9wMgVOw.png" />
</li>
</ul>
</div>
<!--Articles sidebar -->
<div id="sidebar">
<p>Sidebar</p>
</div>
<!-- the footer -->
<div id="footer">
<p>Footer</p>
</div>
</div>
<script>
var columns;
$(document).ready(function() {
$('#gallery_container').masonry({
gutter: 12,
itemSelector: '#gallery_container ul li img',
columnWidth: 150
});
});
</script>
</body>
</html>
CSS
#wrapper {
margin-right: auto;
margin-left: auto;
width: 96%;
}
#header {
margin-right: 1.0416667%; /* 10 div 960 */
margin-left: 1.0416667%; /* 10 div 960 */
width: 97.9166667%; /* 940 div 960 */
background-color: #779307;
}
#navigation {
padding-bottom: 25px;
margin-top: 26px;
margin-left: -1.0416667%; /* 10 div 960 */
padding-right: 1.0416667%; /* 10 div 960 */
padding-left: 1.0416667%; /* 10 div 960 */
width: 97.9166667%; /* 940 div 960 */
}
#navigation ul li {
display: inline;
margin-right: 2.6595745%; /* 25 div 940 */
}
#navigation ul li a {
height: 42px;
line-height: 42px;
text-decoration: none;
text-transform: uppercase;
font-family: Arial, "Lucida Grande", Verdana, sans-serif;
font-size: 27px;
color: black;
}
#content {
margin-top: 58px;
margin-right: 1.0416667%; /* 10 div 960 */
float: right;
background-color: #dedede;
width: 72.7083333%; /* 698 div 960 */
}
#sidebar {
border-right-color: #e8e8e8;
border-right-style: solid;
border-right-width: 2px;
margin-top: 58px;
padding-right: 1.0416667%; /* 10 div 960 */
margin-right: 1.0416667%; /* 10 div 960 */
float: left;
width: 22.7083333%; /* 218 div 960 */
background-color: #fe9c00;
}
#footer {
float: left;
margin-top: 20px;
margin-right: 1.0416667%; /* 10 div 960 */
margin-left: 1.0416667%; /* 10 div 960 */
clear: both;
width: 97.9166667%; /* 940 div 960 */
background-color: #663300;
}
#gallery_container {
list-style-type: none;
padding: 0px;
margin: 0px;
background-color: #302200;
}
#gallery_container ul li {
display: inline;
}
#gallery_container ul li img {
padding-top: 10px;
}
最佳答案
我认为您的 fiddle 不能正常工作...无论如何,有选项 "isFitWidth": true
提示砌体填充所有水平空间。试试吧。
关于html - 使用流体布局移除 Masonry 容器的多余间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23338913/