【问题标题】:Trying to fill a page with pictures in a for loop试图在 for 循环中用图片填充页面
【发布时间】:2021-06-27 17:37:54
【问题描述】:

我有一个用图片填充页面的循环,但它们是垂直填充的。

    {% for i in range(amount) %}
      <div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
       <div class="contents-block">
        <div class="image"><img src="/static/assets/img/uploaded/coro.png" />
        </div>
       </div>
      </div>
    {% endfor %}
   </div>

如何让图片在网格中填满整个页面?

【问题讨论】:

    标签: python html flask layout


    【解决方案1】:

    您的图像在列中排列,因为您的所有 &lt;img&gt; 标记都在父列下。而右侧部分是空的,单张图片没有覆盖整个宽度的原因是图片的大小造成的。

    要回答您关于如何制作覆盖整个宽度的图像网格的问题,我的想法是将所有图像包含在一个 div 中并使用 n

    <div class="images">
        {% for i in range(amount) %}
            <img src="/static/assets/img/uploaded/coro.png" />
        {% endfor %}
    </div>
    

    CSS 将是

    .images {
      /* Prevent vertical gaps */
      line-height: 0;
      column-count: 5; /* this depends on size, no.of images and viewport(for making it responsive) */
      column-gap: 0px;  
    }
    
    .images img {
      width: 100% !important;
      height: auto !important;
      padding: 3px;
    }
    

    【讨论】:

    • 我试过你的解决方案,但它仍然只排在一个列中
    • 对不起 for 循环应该在里面,我编辑了答案,检查一下
    猜你喜欢
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 2020-06-26
    • 2020-04-02
    • 1970-01-01
    • 2012-05-07
    • 2011-09-29
    • 2020-07-18
    相关资源
    最近更新 更多