可以正确格式化此响应网格

时间:2017-11-22 14:27:43

标签: html css grid-layout

我有一个图像网格,我想在这里显示图像:

Grid of Images - how it should be laid out

不幸的是,底行正在向下推出不对齐。

我正在改编Graham Miller的响应式网格系统,这很棒。这是我到目前为止的代码:

CSS:

/*  SECTIONS  */
    .section {
        clear: both;
        padding: 0px;
        margin: 0px;
    }

    /*  COLUMN SETUP  */
    .col {
        display: block;
        float:left;
        margin: 1% 0 1% 1.6%;
    }
    .col:first-child { margin-left: 0; }

    /*  GROUPING  */
    .group:before,
    .group:after { content:""; display:table; }
    .group:after { clear:both;}
    .group { zoom:1; /* For IE 6/7 */ }


    /*  GRID OF SIX  */
    .span_6_of_6 {
        width: 100%;
    }

    .span_5_of_6 {
        width: 83.06%;
    }

    .span_4_of_6 {
        width: 66.13%;
    }

    .span_3_of_6 {
        width: 49.2%;
    }

    .span_2_of_6 {
        width: 32.26%;
        height: 350px;
    }

    .span_1_of_6 {
        width: 15.33%;
    }

    img {
        width: 100%;
        height: auto;
    }
    /*  GO FULL WIDTH BELOW 480 PIXELS */
    @media only screen and (max-width: 480px) {
        .col {  margin: 1% 0 1% 0%; }
        .span_1_of_6, .span_2_of_6, .span_3_of_6, .span_4_of_6, .span_5_of_6, .span_6_of_6 { width: 100%; }
    }

HTML:

<div class="section group">
    <div class="col span_2_of_6"><img src="images/slices02.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices02.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices03.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices04.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices05.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices06.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices07.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices08.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices09.png" alt=""/></div>
</div>
<div class="section group">
    <div class="col span_1_of_6"><img src="images/slices04.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices05.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices06.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices07.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices08.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices09.png" alt=""/></div>
</div>
<div class="section group">
    <div class="col span_1_of_6"><img src="images/slices02.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices03.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices04.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices05.png" alt=""/></div>
    <div class="col span_2_of_6"><img src="images/slices02.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices06.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices07.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices08.png" alt=""/></div>
    <div class="col span_1_of_6"><img src="images/slices09.png" alt=""/></div>
</div>

我尝试过几件事情,包括将左下方五行图像浮动到左边,稍微调整图像大小,以及其他绝望的措施,但都无济于事。

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

实施六柱系统和四柱系统,完成后,您可以执行以下操作:

<div class="section group"> <!-- First row -->
    <div class="col span_2_of_6"> <!-- left side of row -->
        <div class="col span_6_of_6"> <!-- this is for margin consistency -->
            <img src="" alt=""> 
        </div>
    </div>

    <div class="col span_4_of_6"> <!-- right side of row -->
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>

        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
    </div>
</div>

<div class="section group"> <!-- second row -->
    <div class="col span_6_of_6"> <!-- full row -->
        <div class="col span_1_of_6"><img src="" alt=""></div>
        <div class="col span_1_of_6"><img src="" alt=""></div>
        <div class="col span_1_of_6"><img src="" alt=""></div>
        <div class="col span_1_of_6"><img src="" alt=""></div>
        <div class="col span_1_of_6"><img src="" alt=""></div>
        <div class="col span_1_of_6"><img src="" alt=""></div>
    </div>
</div>

<div class="section group"> <!-- Third row -->
    <div class="col span_4_of_6"> <!-- left side of row -->
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>

        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
        <div class="col span_1_of_4"><img src="" alt=""></div>
    </div>

    <div class="col span_2_of_6"> <!-- right side of row -->
        <div class="col span_6_of_6"> <!-- this is for margin consistency -->
            <img src="" alt=""> 
        </div>
    </div>
</div>

您可能需要添加一些自定义类,以便更好地控制边距。