javascript - 完全填满浏览器窗口的多列图像

标签 javascript jquery html css

我希望有很多可点击的图像来覆盖浏览器窗口的宽度。所以两边都没有空间。理想情况下,id 喜欢单个图像的大小保持在 180x180px,但如果更容易,它们可以根据浏览器窗口更改大小。只需要填补空间。目前,如果我使包含的 div 大于主体,它会在右侧产生空间溢出。如果这是有道理的话。

这是我的代码:- http://jsfiddle.net/ZPTBB/

这就是我希望它看起来的样子:- http://www.karen.hunter.myzen.co.uk/pinewood/image_so.jpg

也许它需要查询????

提前感谢您的帮助。

我的代码:-

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Untitled Document</title>
            <style>
            /* Editable Multiple Image Area */
            .image-container {width:100%; margin:0; padding:0; height:360px; overflow:hidden;}
            .image{position:relative;float:left;width:188px;height:188px; margin:0; padding:0;}
            .image img {position:absolute;z-index:1;left:0;top:0;}
            .image:hover div {display:block!important; }
            .image img:hover div {display:none;position:absolute;z-index:2; width:100%; height:100%; background:red;}
            .hoverimg {display:none;position:absolute;z-index:2; width:100%; height:100%; background:red;}
            </style>
            </head>

            <body>
            <!-- IMAGE CONTAINER -->
                  <div class="image-container">
                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>


                       <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>

                        <div class="image">
                            <img src="http://www.placehold.it/188x188" />
                            <div class="hoverimg"><a href="success.html"><img src="_includes/img/global/image.jpg" width="188" height="188" /></a></div>
                        </div>
                  </div><!-- IMAGE CONTAINER -->
            </body>
            </html>

最佳答案

添加一些可以包含溢出图像的额外容器:

.image-container {
    width:100%; 
    height:360px; 
    overflow:hidden;
}
.image-container-overflow {
    width: 100%; 
    padding-right:187px; /* assuming 188px width for image */
    height: 360px; 
    position: relative;
}
.image-container-actual {
    width: 100%; 
    height: 360px; 
    position: absolute;
    top: 0; 
    left: 0
}

第一个通过填充占用 100% + 187px,下一个通过绝对定位占用总数

http://jsfiddle.net/willemvb/pq26W/

关于javascript - 完全填满浏览器窗口的多列图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19585443/

相关文章:

javascript - Meteor - 如何确定是否可以在不引发错误的情况下使用 Meteor.user()?

javascript - 如何使用 RegEx 和 Jquery 隐藏 DIV 元素

javascript - 我可以编写一个函数来打开一个新页面并只显示过滤后的 div 吗?

javascript - 在 iFrame 中应用 CSS

javascript - 使用分布曲线创建直方图,其中曲线系列大于 bin 系列

javascript - 遍历每一行并使 p 标签具有相同的高度

jquery 代码导致不需要的空间

jquery - 使用具有非固定高度/宽度容器的流沙

html - 建仓 :static (or :relative) element span the width of the page

javascript - 使用 sequelize 获取下一条记录