【问题标题】:Putting two images next to each other in Bootstrap在 Bootstrap 中将两个图像并排放置
【发布时间】:2016-05-24 22:24:36
【问题描述】:

我想将这两个图像并排放置,但如果屏幕太小,我希望它们堆叠在一起。这就是我在 Razor 中所拥有的:

<div class="row">

    <div class="col-sm-12">
        @if (Model.ThumbnailUrl != null)
        {
            <span><img class="thumbnail" src="@Model.ThumbnailUrl" /></span>
        }
        @if (Model.SignatureUrl != null)
        {
            <span><img class="thumbnail" src="@Model.SignatureUrl" /></span>

        }
    </div>
</div>

这是生成的:

<div class="row">
        <div class="col-sm-12">
                <span style="display: inline"><img class="thumbnail" src="something.jpg;width=200&amp;height=200"></span>
                <span style="display: inline"><img class="thumbnail" src="whatever.jpg;width=200&amp;height=200"></span>
        </div>       
</div>

这就是它的外观:

它们堆叠得太早了。屏幕是全尺寸的。也许只是小号或超小号我希望它们堆叠,否则我希望它们并排。

我应该如何解决这个问题?

【问题讨论】:

    标签: html css asp.net-mvc twitter-bootstrap razor


    【解决方案1】:

    这里有一个解决方案:

    1/ 使用 Bootstrap 响应类为不同的屏幕尺寸制作 2 列。

    2/ 对图片使用 img-responsive 类,以便在调整大小时使 img 大小适应内容。

    .row.row-no-margin {
      margin-left: 0px;
      margin-right: 0px;
    }
    
    .col-no-padding {
      padding-left: 0 !important;
      padding-right: 0 !important;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="row row-no-margin">
            <div class="col-xs-12 col-sm-6 col-no-padding">
              <img class="thumbnail img-responsive" src="http://placehold.it/600x400">
            </div>
            <div class="col-xs-12 col-sm-6 col-no-padding">
              <img class="thumbnail img-responsive" src="http://placehold.it/600x400">
            </div>
    </div>

    【讨论】:

    • 嗯不知道 img-responsive
    • 我添加了 2 个类来删除 Bootstrap 列之间的空间,如果您希望图像并排。
    【解决方案2】:

    试试这样的:

    <div class="row">
        <div class="col-sm-6">
            @if (Model.ThumbnailUrl != null)
            {
                <span><img class="thumbnail" src="@Model.ThumbnailUrl" /></span>
            }
        </div>
        <div class="col-sm-6">
            @if (Model.SignatureUrl != null)
            {
                <span><img class="thumbnail" src="@Model.SignatureUrl" /></span>
            }
        </div>
    </div>
    

    基本上,您需要使用 Bootstrap 的列来排列图像。现在,您正在为每个图像创建一个大小为 12 的列,即行的整个宽度。

    更多信息: https://getbootstrap.com/examples/grid/

    【讨论】:

    • 我本来是这样的,但后来他们之间会有差距。我希望他们并排。
    猜你喜欢
    • 2016-01-07
    • 1970-01-01
    • 2013-05-09
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多