【问题标题】:Removing excess spacing for Masonry container using fluid layout使用流体布局去除 Masonry 容器的多余间距
【发布时间】:2014-06-13 20:54:24
【问题描述】:

我正在尝试使用 Masonry 创建一个图片库,并且在调整浏览器大小时重新排序图片。

但是,由于我为缩略图图像使用了 150 像素的固定宽度(因此未加载实际的大图像文件),但我无法删除图像容器两侧的访问间距,因为它会缩放基于屏幕大小,宽度使用百分比。

网站布局如下图:

Layout

Actual Layout

请注意,图像容器右侧有多余的间距。总之,

  1. 如何使容器缩放到 Masonry 图像网格的大小,因为图像容器是根据宽度通过百分比计算的?

  2. 将图像固定为 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;  
}

【问题讨论】:

  • 如果你创建了一个 jsfiddle 会更容易,这样我们就可以玩它了,但第一个猜测是尝试制作 #gallery_container display: inline-block 这样它就不会完全伸展其父级的宽度。
  • 嗨,比利,jsfiddle 在这里创建 link

标签: html css jquery-masonry fluid-layout


【解决方案1】:

我认为你的小提琴工作不正常......无论如何,有一个选项"isFitWidth": true 提示砌体填充所有水平空间。试试看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-23
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    相关资源
    最近更新 更多