【问题标题】:Bootstrap Responsive Image GridBootstrap 响应式图像网格
【发布时间】:2017-01-12 06:08:54
【问题描述】:

我想用 Bootstrap 创建一个响应式图像网格。我有 4 张图片,桌面尺寸需要 1x4 网格,移动尺寸需要 2x2 网格。我尝试了以下代码,但桌面大小的图像之间存在不必要的空白。移动尺寸也没有任何空间。如何调整此布局?

提前致谢

<div class="container">
    <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
            <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
            <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
            <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
        </div>
        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
            <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
        </div>
    </div>
</div>

【问题讨论】:

    标签: html css twitter-bootstrap responsive-design responsive-images


    【解决方案1】:

    引导程序中的列上有填充。 我会向您的&lt;div class="row"&gt; 添加一个类,并通过 css 删除列的填充。

    像这样:

    <div class="container">
        <div class="row imagetiles">
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
            </div>
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
            </div>
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
            </div>
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                <img src=https://i.scdn.co/image/2fd8fa0f7ef2f83691a0fb9628ee369b8e3b688e class="img-responsive">
            </div>
        </div>
    </div>
    
        <style>
      div.imagetiles div.col-lg-3.col-md-3.col-sm-3.col-xs-6{
      padding: 0px;
    }
        </style>
    

    JsFiddle Demo

    这会照顾桌面上的空间。 您可以通过 CSS 调整列上的填充来调整图像之间的空间。对于移动设备 - 只需使用媒体查询。 Bootstrap 有以下查询:

    /* Large desktops and laptops */
    @media (min-width: 1200px) {
    
    }
    
    /* Landscape tablets and medium desktops */
    @media (min-width: 992px) and (max-width: 1199px) {
    
    }
    
    /* Portrait tablets and small desktops */
    @media (min-width: 768px) and (max-width: 991px) {
    
    }
    
    /* Landscape phones and portrait tablets */
    @media (max-width: 767px) {
    
    }
    
    /* Portrait phones and smaller */
    @media (max-width: 480px) {
    
    }
    

    例子:

        @media(max-width: 480px){
    div.imagetiles div.col-lg-3.col-md-3.col-sm-3.col-xs-6{
          padding: 5px;}
    }
    

    【讨论】:

    • 对于某些图像,对齐不起作用。我怎样才能解决这个问题?你可以在这里看到一个例子; jsfiddle.net/ovuncuzun/u65qx59w/1
    • 这是因为教父图像的大小与其他 3 个图像不同。教父的图像是 640px x 634px,而其他 3 个是 640px x 640px。
    • 这些图片是随机出现的。我可以将所有图像更改为 640 像素 x 640 像素,尽管它们不在运行时?我正在使用 AngularJS。谢谢
    • 我建议在这个网站上提出一个新问题,描述你的新问题是什么!
    猜你喜欢
    • 1970-01-01
    • 2016-03-03
    • 2017-08-28
    • 2016-08-25
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    相关资源
    最近更新 更多