4

I have three equally divided vertical divs having many divs inside each of the vertical divs as follows.

When browser is not resized

I want the inner divs to wrap to a 2 column or 1 column grid (depending on browser height width) with each divs height width increasing on browser resize. Presently the divs wrap around but still some extra space is left and I want the inner divs to increase in size with browser size decreasing filling that extra space.

Here is the image when i resize the browser

after i resize the browser

My HTML is as follows

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
body {
    height: 100%;
    font-size: 100%;
}

.main {
    border: 2px solid black;
    position: absolute !important;
    width: 100% !important;
    height: 100% !important;
    left: 0px !important;
    top: 0px !important;
    z-index: 1 !important;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    overflow: hidden;
}

.verticalReports {
    width: 32%;
    border: 1px solid black;
    height: 100%;
    float: left;
    overflow:hidden;
}

.verticalTiles {
    width: 30%;
    height: 20%;
    background-color: #e0d8ed;
    margin-left: 10px;
    margin-top: 13px;
    float: left;
}
</style>

</head>
<body>
    <div class="main">
        <div class="verticalReports">
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>

        </div>

        <div class="verticalReports">

            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
        </div>

        <div class="verticalReports">
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
            <div class="verticalTiles"></div>
        </div>
    </div>
</body>
</html>
4

2 回答 2

2

尝试在断点处添加一些媒体查询。

@media (max-width: 940px) {
    .verticalTiles {
        width: 45%;
    }
}

http://jsfiddle.net/ferne97/wh7kD/

可能想研究一些响应式网格,例如http://responsive.gs/http://www.gumbyframework.com/docs/grid

于 2013-02-13T09:31:53.967 回答
1

你不需要javascript。在您的示例中发生的情况是,您有三个 30% 宽的元素,剩余 10 px 边距,当您调整浏览器大小时,三个图块加起来的 30px 小于图块宽度剩余的 10%,它们没有'不适合了,尝试使用边距的相对值,例如 margin-left: 3%

好的,所以根据您的评论,您应该使用以下内容:

    function wiwi() {
    var tenpercent = $('.verticalReports').width() / 10;
    if ( tenpercent < 30 ) {
        $('.verticalTiles').css('width','45%');
    }
}
$(document).ready(function() {
    wiwi();
    $(window).resize(function() {
        wiwi();
    });
});
于 2013-02-13T09:25:12.097 回答